home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / vidhandl / videohlp.txt < prev    next >
Text File  |  1999-02-03  |  171KB  |  4,949 lines

  1. @VIDEO HANDLING FUNCTIONS ver 2.0 INDEX
  2.  
  3. :Introduction:!!!INTRODUCTION
  4. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  5. % ▌Video Handling Functions ▐          <~CRT.H~>
  6. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀                            ver 2.0
  7.  
  8.     The header file <CRT.H> declares a group of functions that can access
  9.   the screen either directly to video RAM or via BIOS calls, being really
  10.   fast (when they use RAM access) and small (all them together takes only
  11.   6.4k in small memory model).
  12.     Access via BIOS is provided to allow them to work in any IBM compatible
  13.   video adapter or in graphics mode.
  14.     They are available in "compact", "small", "medium", "large" and "huge"
  15.   memory models.
  16.  
  17. % Contents:
  18.     ~Functions~
  19.     ~Macro Functions~
  20.     ~Global Variables~
  21.     ~Data types~
  22.     ~Declarations~ of Functions, Macros, Global Variables,...
  23.     ~CRT.H~ header file help
  24.     ~Appendix A~ => Portability
  25.     ~Appendix B~ => Colors
  26.  
  27. :Functions
  28. %FUNCTIONS:
  29.  
  30.     ■ ~crt_detect~      Detects current video mode, active display page,
  31.                       number of columns, rows, current page start address,...
  32.     ■ ~crt_init~        Calls crt_detect and updates crtwin_dta coordinates
  33.                       to full screen and crtwin_just to CENTER_TEXT.
  34.     ■ ~videomode~       Selects the number of columns and rows, via an input
  35.                       argument. (Obsolete function, use crt_detect instead).
  36.     ■ ~setcrtmode~      Changes current video mode, then call getcrtmode.
  37.     ■ ~getcrtmode~      Gets current video mode, number of columns and current
  38.                       page.
  39.     ■ ~setcrtpage~      Selects video display page.
  40.     ■ ~crt_gotoxy~      Changes cursor position.
  41.     ■ ~crt_getxy~       Gets cursor position.
  42.     ■ ~getcrtchar~      Gets the character from screen position (x,y).
  43.     ■ ~getcrtcolor~     Gets the color from screen position (x,y).
  44.     ■ ~biosprintc~      Sends a character into screen at position (x,y) via
  45.                       BIOS.
  46.     ■ ~printcn~         Sends a character at position (x,y) with no color.
  47.     ■ ~printc~          Sends a character to screen with a color.
  48.     ■ ~changecolor~     Changes the color from (x,y) position on screen.
  49.     ■ ~printct~         Changes the character and/or color or keeps old
  50.                       character and/or color of (x,y) position according to
  51.                       a user given parameter.
  52.     ■ ~printsn~         Writes a string at position (x,y) with no color.
  53.     ■ ~prints~          Writes a string at position (x,y) with color.
  54.     ■ ~printxy~         Writes a string on screen in any direction, with color.
  55.     ■ ~printx~          Outputs a string with special text format instructions.
  56.                       Writes the string with color.
  57.     ■ ~printtext~       Writes a string inside current box at position(x,y),
  58.                       continuing in the next line if text doesn't fit in one.
  59.                       Writes string with color.
  60.     ■ ~printsj~         Justified writes a string inside the current text box.
  61.                       Writes string with color.
  62.     ■ ~printsjc~        Enhanced printsj with special text color instructions.
  63.     ■ ~printsnf~        Sends formatted output to screen using printsn.
  64.     ■ ~printsf~         Sends formatted output to screen using prints.
  65.     ■ ~printxyf~        Sends formatted output to screen using printxy.
  66.     ■ ~printxf~         Sends formatted output to screen using printx.
  67.     ■ ~printtextf~      Sends formatted output to screen using printtext.
  68.     ■ ~printsjf~        Sends formatted output to screen using printsj.
  69.     ■ ~printsjcf~       Sends formatted output to screen using printsjc.
  70.  
  71.     ■ ~fillscr~         Fills the screen with a character and a color.
  72.     ■ ~barcolor~        Replaces the color of a text window.
  73.     ■ ~fillbar~         Fills a text window with a character and a color.
  74.     ■ ~fillbarw~        Fills a text window given by crtwin_dta with a
  75.                       character and a color.
  76.     ■ ~fillbox~         Replaces the characters and/or colors or keeps old
  77.                       characters and/or colors of a text window according to a
  78.                       user given parameter.
  79.     ■ ~fillboxw~        Same as fillbox, but text window coordinates are given
  80.                       by crtwin_dta.
  81.     ■ ~crtframe~        Draws a colored text frame (single line, double line,
  82.                       ...) (frame is a text box outline)
  83.     ■ ~crtframew~       Draws a colored text frame with coordinates given by
  84.                       crtwin_dta with single outline, double outline,...
  85.     ■ ~mkline_aux~      It's mkline's character replacement algorithm.
  86.     ■ ~mkline~          Draws frame lines replacing frame line intersections
  87.                       by corresponding characters automatically.
  88.     ■ ~crtwindow~       Draws a text box with border and title.
  89.     ■ ~savevideo~       Saves the screen contents into a buffer.
  90.     ■ ~restorevideo~    Writes a drawing saved in a buffer into screen.
  91.     ■ ~savevideowin~    Saves a text window into a buffer.
  92.     ■ ~restorevideowin~ Writes a drawing saved in a buffer into a text window
  93.     ■ ~savevideow~      Saves a text window given by crtwin_dta into a buffer.
  94.     ■ ~restorevideow~   Writes a drawing saved in a buffer into a text window
  95.                       given by crtwin_dta.
  96.     ■ ~savecrt~*        Saves the screen contents into a buffer with mode.
  97.     ■ ~restorecrt~*     Writes a drawing saved in a buffer into screen with
  98.                       mode.
  99.     ■ ~savecrtwin~*     Saves a text window into a buffer with mode.
  100.     ■ ~restorecrtwin~*  Writes a drawing saved in a buffer into a text window
  101.                       with mode.
  102.     ■ ~savecrtw~*       Saves a text window given by crtwin_dta into a buffer
  103.                       with mode.
  104.     ■ ~restorecrtw~*    Writes a drawing saved in a buffer into a text window
  105.                       given by crtwin_dta with mode.
  106.  
  107.     ■ ~setcursorsh~     Changes cursor shape.
  108.     ■ ~getcursorsh~     Gets cursor current shape.
  109.     ■ ~setpalreg~       Sets a single palette register color (DAC register)
  110.     ■ ~getpalreg~       Reads the color (DAC register) from a single palette
  111.                       register.
  112.     ■ ~setbordercolor~  Sets the border(overscan) color (DAC register)
  113.     ■ ~getbordercolor~  Reads the border (overscan) color (DAC register)
  114.     ■ ~setdacreg~       Sets the rgb color of a DAC register.
  115.     ■ ~getdacreg~       Reads the rgb color of a DAC register.
  116.     ■ ~setdacpage~      Selects video DAC color page.
  117.     ■ ~setdacpgmode~    Selects video DAC paging mode.
  118.     ■ ~getdacpgstate~   Gets current video DAC color page and paging mode.
  119.     ■ ~setchrboxwidth~  Changes the character box width in VGA or better
  120.                       monitors.
  121.     ■ ~settextblink~    Toggles color/attribute intensity/blinking bit.
  122.     ■ ~changechar~      Replaces text mode character patterns with user
  123.                       specified patterns
  124.     ■ ~changecharg~     Replaces graphics mode character patterns with user
  125.                       specified patterns
  126.  
  127.  
  128.   * To use them is needed to be defined a macro before including CRT.H, see
  129.   ~CRT_FULL~
  130.  
  131. % See Also:
  132.     ~Macro Functions~   ~Declarations~ of functions
  133.  
  134. % Return to:
  135.     ~Introduction~   ~CRT.H~
  136.  
  137. :Macro Functions
  138. %MACRO FUNCTIONS:
  139.  
  140.     ■ ~crtframe~ function:
  141.        ■ ~moldura~      Draws a text frame with single outline (type = 0).
  142.        ■ ~moldurad~     Draws a text frame with double outline (type = 1).
  143.  
  144.     ■ ~crtframew~ function: (text frame coordinates given by crtwin_dta)
  145.        ■ ~molduraw~     Draws a text frame with single outline (type = 0).
  146.        ■ ~molduradw~    Draws a text frame with double outline (type = 1).
  147.  
  148.  
  149.     ■ ~mkline~ function:
  150.        ■ ~linha_hor~    Draws a horizontal line with single outline.
  151.        ■ ~linha_ver~    Draws a vertical line with single outline.
  152.        ■ ~linhad_hor~   Draws a horizontal line with double outline.
  153.        ■ ~linhad_ver~   Draws a vertical line with double outline.
  154.  
  155.     ■ ~crtwindow~ function:
  156.        ■ ~janela~       Draws a text box with single outline.
  157.        ■ ~janelad~      Draws a text box with double outline.
  158.  
  159.     ■ ~setcrtwin~       Defines active text box used by printsj and crtwindow.
  160.                       Changes crtwin_dta global variable.
  161.  
  162.     ■ ~savevideo~       Is a macro when defined ~CRT_FULL~ or ~SAVECRT·~
  163.     ■ ~restorevideo~    Is a macro when defined ~CRT_FULL~ or ~RESTORECRT·~
  164.     ■ ~savevideowin~    Is a macro when defined ~CRT_FULL~ or ~SAVECRTWIN·~
  165.     ■ ~restorevideowin~ Is a macro when defined ~CRT_FULL~ or ~RESTORECRTWIN·~
  166.     ■ ~savevideow~      Is a macro when defined ~CRT_FULL~ or ~SAVECRTWIN·~
  167.     ■ ~restorevideow~   Is a macro when defined ~CRT_FULL~ or ~RESTORECRTWIN·~
  168.  
  169. % See Also:
  170.     ~Functions~
  171.  
  172. % Return to:
  173.     ~Introduction~   ~CRT.H~
  174.  
  175. :Global Variables
  176. %GLOBAL VARIABLES:
  177.  
  178.     ■  ~vmode_x~    =>  tells the expected number of columns in current text
  179.                       mode.
  180.     ■  ~vmode_y~    =>  tells the expected number of rows in current text mode.
  181.     ■  ~vmode_mode~ =>  tells the expected video mode.
  182.     ■  ~crt_direct~ =>  determines if the screen access goes directly to video
  183.                       RAM (crt_direct==0) or via BIOS calls. (crt_direct!=0).
  184.                       (default == 0)
  185.     ■  ~crt_page~   =>  defines the text page that must be used by the
  186.                       functions when they use access via BIOS. (default == 0).
  187.     ■  ~video_addr~ =>  text mode video RAM base address. (Used when
  188.                       crt_direct=0) (default = B800:0000h).
  189.     ■  ~crt_EVGA_addr~ => determines EGA/VGA/SVGA adapter base port address.
  190.                             (default (primary) = 3C0h / alternate = 2C0h)
  191.  
  192.     ■  ~crtframe_mat~  => array that holds the characters used by crtframe.
  193.     ■  ~mkline_mat~    => array that holds the characters used by mkline and
  194.                         mkline_aux.
  195.     ■  ~crtwin_just~   => defines if text outputted by printsj will be left
  196.                         justified, or center justified or right justified.
  197.     ■  ~crtwin_dta~    => a struct that defines the active text box or text
  198.                         window (that is used by printsj and crtwindow)
  199.                         coordinates. See (struct ~crtwin~) type.
  200.     ■  ~changechar_height~ => determines character pattern size (in bytes) and
  201.                             height (in bits). Used by changechar and
  202.                             changecharg.
  203.     ■  ~changechar_func~   => _AX value in call to changechar. determines if
  204.                             number of screen rows is recalculated or not.
  205.     ■  ~changechar_blk~    => block to load character patterns in map 2. used
  206.                             by changechar.
  207.  
  208.   Remark: vmode_x and vmode_y can be changed to any value intending to obtain
  209.     interesting effects.
  210.        All variables above can be accessed by the programmer. However, there
  211.     are some global variables which are for exclusive and internal use of the
  212.     functions. They are: crtvar_p, vmode_lm and vmode_am (if I haven't
  213.     forgotten any)
  214.  
  215. % See Also:
  216.     ~Data Types~
  217.  
  218. % Return to:
  219.     ~Introduction~   ~CRT.H~
  220.  
  221. :Data Types
  222. %DATA TYPES:
  223.  
  224.     ■  ~crtwin~      => struct that holds a window or box coordinates.
  225.     ■  ~crtwin_inp~  => The structure of input arguments of crtwindow function.
  226.  
  227. % See Also:
  228.     ~Global Variables~
  229.  
  230. % Return to:
  231.     ~Introduction~   ~CRT.H~
  232.  
  233.  
  234. :Declarations
  235. %DECLARATION OF FUNCTIONS:
  236.  
  237.  void ~crt_detect~   (int mode);
  238.  void ~crt_init~     (int mode);
  239.  void ~videomode~    (int newmode);
  240.  void ~setcrtmode~   (int mode);
  241.  int  ~getcrtmode~   (void);
  242.  void ~setcrtpage~   (int page);
  243.  void ~crt_gotoxy~   (int x,  int y);
  244.  int  ~crt_getxy~    (int *x, int *y);
  245.  int  ~getcrtchar~   (int x,  int y);
  246.  int  ~getcrtcolor~  (int x,  int y);
  247.  void ~biosprintc~   (int chr, int x, int y, int color, int func);
  248.  void ~printcn~      (int c, int x, int y);
  249.  void ~printc~       (int c, int x, int y, int color);
  250.  void ~changecolor~  (int x, int y, int color);
  251.  void ~printct~      (int c, int x, int y, int color, unsigned int type);
  252.  void ~printsn~      (char *s, int x, int y);
  253.  void ~prints~       (char *s, int x, int y, int color);
  254.  void ~printxy~      (char *s, int x, int y, int dx, int dy, int color);
  255.  void ~printx~       (char *s, int x, int y, int color);
  256.  int  ~printtext~    (char *s, int x, int y, int color);
  257.  void ~printsj~      (char *s, int y, int color);
  258.  void ~printsjc~     (char *s, int y, int color);
  259.  int  ~printsnf~     (int x, int y,                            char *fmt,... );
  260.  int  ~printsf~      (int x, int y,                 int color, char *fmt,... );
  261.  int  ~printxyf~     (int x, int y, int dx, int dy, int color, char *fmt,... );
  262.  int  ~printxf~      (int x, int y,                 int color, char *fmt,... );
  263.  int  ~printtextf~   (int x, int y, int color, char *fmt,... );
  264.  int  ~printsjf~     (int y, int color, char *fmt,... );
  265.  int  ~printsjcf~    (int y, int color, char *fmt,... );
  266.  void ~fillscr~   (int c, int color);
  267.  void ~barcolor~  (int xi, int yi, int xf, int yf, int color);
  268.  void ~fillbar~   (int c, int xi, int yi, int xf, int yf, int color);
  269.  void ~fillbarw~  (int c, int color);
  270.  void ~fillbox~   (int c, int xi, int yi, int xf, int yf, int color, int func);
  271.  void ~fillboxw~  (int c, int color, int func);
  272.  void ~crtframe~  (int xi, int yi, int xf, int yf, int color, unsigned type);
  273.  void ~crtframew~    (int color, unsigned int type);
  274.  void ~mkline_aux~   (int cnt, int var, unsigned mode, int pos, int color);
  275.  void ~mkline~       (int cnt, int bgn, int end, int color, unsigned mode);
  276.  void ~crtwindow~    (struct crtwin_inp p0);
  277.  char far *~savevideo~        (char far *s);
  278.  char far *~restorevideo~     (char far *s);
  279.  char far *~savevideowin~     (char far *s, int xi, int yi, int xf, int yf);
  280.  char far *~restorevideowin~  (char far *s, int xi, int yi, int xf, int yf);
  281.  char far *~savevideow~       (char far *s);
  282.  char far *~restorevideow~    (char far *s);
  283.  char far *~savecrt~          (char far *s, int mode);
  284.  char far *~restorecrt~       (char far *s, int mode);
  285.  char far *~savecrtwin~    (char far *s, int xi,int yi,int xf,int yf,int mode);
  286.  char far *~restorecrtwin~ (char far *s, int xi,int yi,int xf,int yf,int mode);
  287.  char far *~savecrtw~      (char far *s, int mode);
  288.  char far *~restorecrtw~   (char far *s, int mode);
  289.  void ~setcursorsh~     (unsigned shape);
  290.  int  ~getcursorsh~     (void);
  291.  int  ~getpalreg~       (int regpal);
  292.  void ~setpalreg~       (int regpal, int val);
  293.  int  ~getbordercolor~  (void);
  294.  void ~setbordercolor~  (int val);
  295.  void ~getdacreg~    (int dacreg, char *red, char *green, char *blue);
  296.  void ~setdacreg~    (int dacreg, char  red, char  green, char  blue);
  297.  void ~setdacpgmode~ (int pgmode);
  298.  void ~setdacpage~   (int page);
  299.  int  ~getdacpgstate~   (void);
  300.  void ~setchrboxwidth~  (int cmd);
  301.  void ~settextblink~    (int cmd);
  302.  void ~changechar~   (unsigned char *fmt, int ind, int qt);
  303.  void ~changecharg~  (unsigned char *fmt, int rows);
  304.  
  305.  
  306. %DECLARATION OF MACROS:
  307.  
  308.  void  ~moldura~  (int xi, int yi, int xf, int yf, int color);
  309.  void  ~moldurad~ (int xi, int yi, int xf, int yf, int color);
  310.  void  ~molduraw~    (int color);
  311.  void  ~molduradw~   (int color);
  312.  void  ~linha_hor~  (int y, int xi, int xf, int color);
  313.  void  ~linha_ver~  (int x, int yi, int yf, int color);
  314.  void  ~linhad_hor~ (int y, int xi, int xf, int color);
  315.  void  ~linhad_ver~ (int x, int yi, int yf, int color);
  316.  void  ~janela~   (struct crtwin_inp p0);
  317.  void  ~janelad~  (struct crtwin_inp p0);
  318.  void  ~setcrtwin~  (int xi, int yi, int xf, int yf);
  319.  
  320.  char far *~savevideo~        (char far *s);
  321.  char far *~restorevideo~     (char far *s);
  322.  char far *~savevideowin~     (char far *s, int xi, int yi, int xf, int yf);
  323.  char far *~restorevideowin~  (char far *s, int xi, int yi, int xf, int yf);
  324.  char far *~savevideow~       (char far *s);
  325.  char far *~restorevideow~    (char far *s);
  326.  
  327.  Remark: savevideo, restorevideo, savevideowin, restorevideowin, savevideow
  328.   and restorevideow are macros if ~CRT_FULL~ is defined before the line.
  329.    #include <CRT.H>
  330.  
  331.  
  332. %DECLARATION OF GLOBAL VARIABLES:
  333.  
  334.  int ~vmode_x~;
  335.  int ~vmode_y~;
  336.  int ~vmode_mode~;
  337.  int ~crt_direct~;
  338.  int ~crt_page~;
  339.  int ~crtwin_just~;
  340.  struct crtwin ~crtwin_dta~;
  341.  char far *~video_addr~;
  342.  const char ~crtframe_mat~[];
  343.  const char ~mkline_mat~[];
  344.  int ~changechar_height~;
  345.  int ~changechar_func~;
  346.  int ~changechar_blk~;
  347.  int ~crt_EVGA_addr~;
  348.  
  349.  
  350. %GENERAL DESCRIPTION OF ARGUMENTS:
  351.  
  352.  x,y   => Start position, or the position where a character or attribute is
  353.           read or written. Where: x=> column; y=> row (or line).
  354.            Remark: The upper left corner is the position (0,0) for all functions
  355.            declared in CRT.H
  356.  chr,c => character.
  357.  color => color.
  358.  s     => string to be outputted or buffer for ...video... or ...crt...
  359.  xi,yi => Start position (upper left corner)
  360.  xf,yf => End position (lower right corner)
  361.  (for other variables see functions helps)
  362.  
  363. % Return to:
  364.     ~Introduction~   ~CRT.H~
  365.  
  366. :CRT.H
  367. %  ▄▄▄▄▄▄▄
  368. %   CRT.H
  369. %  ▀▀▀▀▀▀▀
  370. %  Functions
  371. %  ▀▀▀▀▀▀▀▀▀
  372.     ~barcolor~        ~biosprintc~      ~changechar~      ~changecharg~
  373.     ~changecolor~     ~crt_detect~      ~crt_getxy~       ~crt_gotoxy~
  374.     ~crt_init~        ~crtframe~        ~crtframew~       ~crtwindow~
  375.     ~fillbar~         ~fillbarw~        ~fillbox~         ~fillboxw~
  376.     ~fillscr~         ~getbordercolor~  ~getcrtchar~      ~getcrtcolor~
  377.     ~getcrtmode~      ~getcursorsh~     ~getdacpgstate~   ~getdacreg~
  378.     ~getpalreg~       ~janela~          ~janelad~         ~linha_hor~
  379.     ~linha_ver~       ~linhad_hor~      ~linhad_ver~      ~mkline~
  380.     ~mkline_aux~      ~moldura~         ~moldurad~        ~molduradw~
  381.     ~molduraw~        ~printc~          ~printcn~         ~printct~
  382.     ~prints~          ~printsf~         ~printsj~         ~printsjc~
  383.     ~printsjcf~       ~printsjf~        ~printsn~         ~printsnf~
  384.     ~printtext~       ~printtextf~      ~printx~          ~printxf~
  385.     ~printxy~         ~printxyf~        ~restorecrt~      ~restorecrtw~
  386.     ~restorecrtwin~   ~restorevideo~    ~restorevideow~   ~restorevideowin~
  387.     ~savecrt~         ~savecrtw~        ~savecrtwin~      ~savevideo~
  388.     ~savevideow~      ~savevideowin~    ~setbordercolor~  ~setchrboxwidth~
  389.     ~setcrtmode~      ~setcrtpage~      ~setcrtwin~       ~setcursorsh~
  390.     ~setdacpage~      ~setdacpgmode~    ~setdacreg~       ~setpalreg~
  391.     ~settextblink~    ~videomode~
  392.  
  393. %  Constants, data types, and global variables
  394. %  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  395.     ~BKCOLOR~           ~CHANGCHR_NORM~     ~CHANGCHR_RECALC~
  396.     ~CRT_FULL~          ~CRT_COLORS~        ~DACPAGE_16~
  397.     ~DACPAGE_64~        ~RESTORECRT·~       ~RESTORECRTWIN·~
  398.     ~SAVECRT·~          ~SAVECRTWIN·~       ~TEXTBLINK~
  399.  
  400.     ~crt_EVGA_addr~     ~changechar_height~ ~changechar_func~
  401.     ~changechar_blk~    ~crt_direct~        ~crt_page~
  402.     ~crtframe_mat~      ~crtwin~            ~crtwin_dta~
  403.     ~crtwin_inp~        ~crtwin_just~       ~mkline_mat~
  404.     ~video_addr~        ~vmode_mode~        ~vmode_x~
  405.     ~vmode_y~
  406.  
  407. %  See Also
  408. %  ▀▀▀▀▀▀▀▀
  409.     ~List of all Header files~   ~Pre-compiled headers~   CRT.H file
  410.  
  411. %  Return to:
  412.     ~Introduction~
  413.  
  414. :CRT_COLORS:BKCOLOR:TEXTBLINK
  415. %   CRT_COLORS                         <CRT.H>
  416. %  ▀▀▀▀▀▀▀▀▀▀▀▀
  417.     Enumerated Constants for color.
  418.  
  419.     CRT_COLORS is equivalent to ~COLORS~
  420.  
  421.     Constant     │Value
  422.    ══════════════╪═════
  423.     BLACK        │  0
  424.     BLUE         │  1
  425.     GREEN        │  2
  426.     CYAN         │  3
  427.     RED          │  4
  428.     MAGENTA      │  5
  429.     BROWN        │  6
  430.     LIGHTGRAY    │  7
  431.     DARKGRAY     │  8
  432.     LIGHTBLUE    │  9
  433.     LIGHTGREEN   │ 10
  434.     LIGHTCYAN    │ 11
  435.     LIGHTRED     │ 12
  436.     LIGHTMAGENTA │ 13
  437.     YELLOW       │ 14
  438.     WHITE        │ 15
  439.    ──────────────┼─────
  440.     BKCOLOR      │ 16 *
  441.    ──────────────┼─────
  442.     TEXTBLINK    │128 **
  443.  
  444.    Colors 0 through 15 are foreground colors if alone, but you can set a
  445.  foreground and background color by multiplying the desired background color
  446.  (0 - 15) by BKCOLOR and adding it to the desired foreground color.
  447.    * BKCOLOR is only defined in CRT.H
  448.    ** TEXTBLINK is the same of ~BLINK~
  449.  
  450.    These colors can be redefined in an EGA/VGA/SVGA adapter with ~setpalreg~
  451.  or ~setdacreg~ (VGA/SVGA)
  452.  
  453. % See Also:
  454.     ~Appendix B~
  455.  
  456. :vmode_x:vmode_y
  457. % vmode_x and vmode_y                  <~CRT.H~>
  458. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  459.     vmode_x and vmode_y tells the VIDEO HANDLING FUNCTIONS (prototyped in CRT.H
  460.   the screen shape (number of columns and rows).
  461.  
  462.    ■ vmode_x stores the expected number of columns by CRT functions.
  463.    ■ vmode_y stores the expected number of rows by CRT functions.
  464.  
  465. % Declaration:
  466.    ■ int vmode_x;
  467.    ■ int vmode_y;
  468.  
  469. % Remarks:
  470.     These global variables defines the number of rows and columns of current
  471.   text mode (or text mode that should be selected).
  472.  
  473.     The default values for vmode_x and vmode_y are: 80, 25, respectively.
  474.  
  475.     Note that vmode_x and vmode_y doesn't store the actual number of rows
  476.   and columns of the current text mode. They store the expected number of
  477.   rows and columns, delimiting the area that can be used by the functions
  478.   declared in CRT.H, so if the value of vmode_x or vmode_y is different from
  479.   the actual number of columns or rows, these functions will write and read
  480.   at unexpected position, which can be used to obtain interesting effects,
  481.   without need of extra logic. * * * Do some tests with a little different
  482.   values for vmode_x and vmode_y than normal. They can be changed to any value,
  483.   but beware the danger of loosing important data with very big values.
  484.  
  485.     Also remember that very big values may cause segment overflow. If this
  486.   occurs a character that was expected to be written in another text video
  487.   page, or at the bottom of current page (if page has >100 lines) will be
  488.   written closer to the top.
  489.  
  490.     To update vmode_x and vmode_y to actual number of columns and lines on
  491.   screen use ~crt_detect~ or ~crt_init~.
  492.  
  493.     All functions declared in CRT.H consider the upper left corner as being
  494.   position (0,0), the same as BIOS. Most C and C++ functions consider the upper
  495.   left corner as being position (1,1).
  496.  
  497. % See Also:
  498.     All ~global variables~ list             ~crt_direct~    ~video_addr~
  499.  
  500. :vmode_mode
  501. %  vmode_mode                          <~CRT.H~>
  502. % ▀▀▀▀▀▀▀▀▀▀▀▀
  503.     Defines current (or expected) video mode.
  504.  
  505. % Declaration:
  506.     int vmode_mode;
  507.  
  508. % Remarks:
  509.     vmode_mode is used to tell the programmer the current video mode. The
  510.   default value is 3. Notice that not always the value stored in vmode_mode
  511.   is the actual current mode. To update it to current video mode value
  512.   use one of the folowwing:
  513.     ~setcrtmode~, ~getcrtmode~, ~crt_detect~ or ~crt_init~ call.
  514.  
  515. % See also:
  516.     ~crt_page~   ~crt_direct~   ~video_addr~   ~vmode_x~   ~vmode_y~
  517.  
  518. :crt_direct
  519. %  crt_direct                          <~CRT.H~>
  520. % ▀▀▀▀▀▀▀▀▀▀▀▀
  521.   Controls video access.
  522.  
  523. % Declaration:
  524.     int crt_direct;
  525.  
  526. % Remarks:
  527.    crt_direct defines if the video access is done directly to video RAM
  528.    (video map) or via BIOS calls
  529.  
  530.   Value│ Meaning
  531.   ═════╪══════════════════════════════════════════════
  532.     0  │ (Default) Defines direct video RAM access
  533.     1  │ Defines access via BIOS calls (int 10h)
  534.     >1 │ Same as value 1, but are reserved for future versions
  535.  
  536.     If you set crt_direct to direct video RAM access (default), your system's
  537.   video hardware must be compatible with IBM display adapters, and text mode
  538.   must be set, otherwise the video handling functions won't work properly.
  539.   The advantage of this mode is that functions are executed extremely fast.
  540.   (Tests done under Windows 3.11/95 have shown that these functions work fine
  541.   in a DOS-PROMPT box even if crt_direct==0)
  542.  
  543.     If you set crt_direct to access via BIOS, these functions will work in any
  544.   IBM-BIOS compatible system and even in graphics mode, however they will be
  545.   executed much slower (hundreds time slower!).
  546.  
  547.     To detect if current video mode is a text mode or a graphics mode, use
  548.   crt_detect or crt_init. These functions automatically updates crt_direct
  549.   according to current video mode. If current video mode is a text mode,
  550.   crt_direct=0. If current mode is a graphics mode, crt_direct=1. It works
  551.   in almost every cases.
  552.  
  553.     If you use graphics mode or if you need it to work in any video hardware,
  554.   then you might need to change crt_direct value to 1, for video handling
  555.   functions work properly. (except for few functions that use always
  556.   BIOS calls), because with crt_direct==0, these function outputs/reads only
  557.   from text video RAM, which is not active and possibly disabled when graphics
  558.   mode is selected.
  559.  
  560.     The access via BIOS calls has been provided to increase portability. (this
  561.   allows these functions working in almost any video hardware and even in
  562.   graph mode, but note that it isn't selected by default, as it is very slow.
  563.  
  564.   IMPORTANT: Although any other value than zero or 1 will have the same effect
  565.   as 1, it's not advisable to use any other value than specified, as them are
  566.   reserved for future versions.
  567.  
  568. % See Also:
  569.     All ~global variables~ list     ~crt_detect~   ~crt_init~   ~video_addr~
  570.  
  571. :crt_page
  572. %  crt_page                            <~CRT.H~>
  573. % ▀▀▀▀▀▀▀▀▀▀
  574.   Selects the video page which will be used when the functions write or
  575.   read via BIOS.
  576.  
  577. % Declaration:
  578.     int crt_page;
  579.  
  580. % Remarks:
  581.     crt_page selects the video page that will be used by the functions, when
  582.   they use BIOS calls.
  583.     The default value is 0.
  584.  
  585.   To update crt_page to active display page number, use ~getcrtmode~,
  586.   ~crt_detect~ or ~crt_init~.
  587.  
  588. % See Also:
  589.     All ~global variables~ list     ~vmode_mode~  ~crt_direct~  ~video_addr~
  590.  
  591.  
  592. :video_addr
  593. %  video_addr                          <~CRT.H~>
  594. % ▀▀▀▀▀▀▀▀▀▀▀▀
  595.   Defines text video RAM (video map) base address.
  596.  
  597. % Declaration:
  598.     char far *video_addr;
  599.  
  600.     video_addr defines the memory address where begins the video map or video
  601.   RAM in text mode. Is the memory address where is written or read the
  602.   character at position (0,0), when crt_direct==0. The default value is
  603.   B800:0000h
  604.  
  605. % Remarks:
  606.     video_addr can be changed to different values if the video RAM starts at a
  607.   different memory address, or if the programmer desires to obtain interesting
  608.   effects.
  609.     When changing video_addr to another value left a low OFFSET value to avoid
  610.   the possibility of segment overflow that will cause the data to be read or
  611.   written in a smaller memory address position than expected. This is specially
  612.   dangerous if that memory position is being used by another program. Another
  613.   solution would be to use huge pointers.
  614.     Beware of important data loss if video_addr points to an memory address
  615.   used by a program or operating system.
  616.  
  617.     The functions that writes at video RAM have an internal protection that
  618.   prevents them from writing outside the area that is delimited by video_addr,
  619.   vmode_x and vmode_y, which means that they can only write into a memory area
  620.   that goes from (video_addr) thru (video_addr + 2 * vmode_x * vmode_y - 1).
  621.   To exceed this limit, increase the value of vmode_y or decrease the
  622.   video_addr segment.
  623.     video_addr is used only when crt_direct==0.
  624.  
  625.     To update video_addr to current video page start address use crt_detect or
  626.   crt_init.
  627.  
  628.     video_addr is also changed by a setcrtpage call
  629.  
  630. % See Also:
  631.     All ~global variables~ list        ~vmode_x~  ~vmode_y~  ~crt_direct~
  632.       ~far~ pointers      ~huge~ pointers  ~crt_detect~  ~crt_init~
  633.  
  634. :crt_EVGA_addr
  635. %  crt_EVGA_addr                       <~CRT.H~>
  636. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  637.   crt_EVGA_addr determines EGA/VGA+ adapter base I/O port address.
  638.  
  639. % Declaration:
  640.     int crt_EVGA_addr;
  641.  
  642. % Remarks:
  643.    crt_EVGA_addr is used by some VIDEO HANDLING FUNCTIONS routines that
  644.  access directly the video adapter through I/O ports.
  645.  
  646.    Change the value of crt_EVGA according to the video adapter you are going
  647.  to use:
  648.  
  649.    Value │ Video adapter
  650.   ═══════╪═════════════════════════════════════
  651.    3C0h  │ (Default) primary EGA/VGA+
  652.    2C0h  │ alternate EGA/VGA+
  653.  
  654.    Beware of hardware installed at 2C0h.
  655.  
  656. % See Also:
  657.     All ~global variables~ list
  658.  
  659.  
  660. :crtframe_mat:mkline_mat
  661. %  crtframe_mat and mkline_mat         <~CRT.H~>
  662. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  663.  
  664.   ■ crtframe_mat is an array used by ~crtframe~.
  665.   ■ mkline_mat is an array used by ~mkline_aux~ and ~mkline~.
  666.  
  667. % Declaration:
  668.   ■ const char crtframe_mat[];
  669.   ■ const char mkline_mat[];
  670.  
  671. % Remarks:
  672.  
  673.     The programmer will be able to read characters from these arrays, but
  674.   won't be able to change them, because they are declared in CRT.H as
  675.   constants. To change them remove the "const" keyword (in CRT.H) before
  676.   their declaration.
  677.     They are:
  678.  
  679.     ■ const char crtframe_mat[]="┌─┐│┘─└│╔═╗║╝═╚║▐▀▌▌▌▄▐▐████████";
  680.  
  681.     ■ const char mkline_mat[]="\
  682.     ─   ═\
  683.   ┌┐┬ ╒╕╤\
  684.   └┘┴ ╘╛╧\
  685.  │├┤┼│╞╡╪\
  686.     ─   ═\
  687.   ╓╖╥ ╔╗╦\
  688.   ╙╜╨ ╚╝╩\
  689.  ║╟╢╫║╠╣╬\
  690.  ";
  691.  
  692.   Note that in mkline_mat:
  693.   The blank spaces represents character FFh.
  694.   Each row has eight elements. The first is mkline_mat[0], and the last is
  695.   mkline_mat[63].
  696.  
  697. % See Also:
  698.     All ~global variables~ list
  699.  
  700. :crtwin_just
  701. %  crtwin_just                         <~CRT.H~>
  702. % ▀▀▀▀▀▀▀▀▀▀▀▀▀
  703.   Controls the text justification for ~printsj~... functions, inside active
  704.   text box.
  705.  
  706. % Declaration:
  707.     int crtwin_just;
  708.  
  709. % Remarks:
  710.     The default value is 1 (CENTER_TEXT)
  711.     You may also use the symbolic constants defined by text_just enum declared
  712.   in GRAPHICS.H
  713.  
  714.         Constant    │Value│ Meaning
  715.        ═════════════╪═════╪═════════════════════
  716.         LEFT_TEXT   │  0  │ Left-justify text
  717.         CENTER_TEXT │  1  │ Center text
  718.         RIGHT_TEXT  │  2  │ Right-justify text
  719.  
  720.     crtwin_just only affects ~printsj~, ~printsjc~, ~printsjf~ and ~printsjcf~
  721.   and is affected by ~crt_init~.
  722.  
  723. % See Also:
  724.     All ~global variables~ list     ~text_just~
  725.  
  726. :crtwin_dta
  727. %  crtwin_dta                          <~CRT.H~>
  728. % ▀▀▀▀▀▀▀▀▀▀▀▀
  729.     A ~crtwin~ struct that defines the active text box (text window) (that is
  730.   used by printsj and crtwindow) coordinates. Note that this active text
  731.   window has no relationship with ~window~ function defined in ~CONIO.H~.
  732.     It's value may be loaded from another crtwin struct or via ~setcrtwin~
  733.   macro.
  734.  
  735. % Default values are:
  736.        crtwin_dta.left=-1      crtwin_dta.right=80
  737.        crtwin_dta.top=-1     crtwin_dta.bottom=25
  738.  
  739. % See Also:
  740.     All ~global variables~ list      ~setcrtwin~
  741.  
  742. :crtwin
  743. %  crtwin                              <~CRT.H~>
  744. % ▀▀▀▀▀▀▀▀
  745.     Structure type used to store text windows or text box coordinates.
  746.  
  747.     struct crtwin
  748.      {
  749.        int left;
  750.        int top;
  751.        int right;
  752.        int bottom;
  753.      };
  754.  
  755. % See Also:
  756.     ~crtwin_dta~
  757.  
  758. :crtwin_inp
  759. %  crtwin_inp                          <~CRT.H~>
  760. % ▀▀▀▀▀▀▀▀▀▀▀▀
  761.     The structure of the values passed to ~crtwindow~ function call.
  762.  
  763.     struct crtwin_inp
  764.      {
  765.        char *title; //Text Box Title (if title==NULL doesn't print title)
  766.        int tcolor; //Title color
  767.        int fchr;   //character used to fill window internal area
  768.        int fcolor; //internal window area color
  769.        int bcolor; //box border color
  770.        int btype;  //box border type, same as crtframe
  771.      };
  772.  
  773. % See Also:
  774.    ~crtwin~     ~crtwindow~
  775.  
  776. :crt_detect:crt_init
  777. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  778. % ▌crt_detect and crt_init▐            <~CRT.H~>
  779. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  780.     ■ crt_detect      Detects current video mode, number of columns, rows, video
  781.                       page, current page start address,...
  782.     ■ crt_init        Calls crt_detect and updates crtwin_dta coordinates and
  783.                       crtwin_just to CENTER_TEXT.
  784.  
  785. % Declaration:
  786.     ■ void crt_detect (int mode);
  787.     ■ void crt_init   (int mode);
  788.  
  789. % Remarks:
  790.     crt_detect detects current video mode, active display page, number of
  791.   screen columns and rows. It also detects active display page base address
  792.   and if current mode is a text or graphics mode.
  793.  
  794.     After a call to crt_detect, CRT.H global variables are updated as follow:
  795.   ~vmode_mode~ = current video mode
  796.   ~crt_page~   = active video page
  797.   ~crt_direct~ = 0 if current mode is a text mode;
  798.              = 1 if current mode is a graphics mode
  799.   ~video_addr~ = active video page base address(if current mode is a text mode)
  800.   ~vmode_x~    = number of columns of current mode
  801.   ~vmode_y~    = number of rows on screen
  802.  
  803.     crt_init calls crt_detect and after updates ~crtwin_dta~ and ~crtwin_just~
  804.   as follows:
  805.  
  806.   crtwin_dta.left   = -1
  807.   crtwin_dta.top    = -1
  808.   crtwin_dta.right  = vmode_x
  809.   crtwin_dta.bottom = vmode_y
  810.   crtwin_just       = 1 (CENTER_TEXT)
  811.  
  812.     The main reason to call crt_detect directly is to keep crtwin_dta
  813.   coordinates and crtwin_just unchanged and update CRT.H global variables
  814.   listed above.
  815.  
  816.     mode specifies the system video adapter, according to the table below
  817.  
  818.       Value  │ Video adapter
  819.     ═════════╪═════════════════════════════════
  820.      1       │ CGA
  821.      2       │ MCGA *
  822.      3,4,5   │ EGA  *
  823.      9       │ VGA, SVGA or better
  824.  
  825.    * Not tested.
  826.  
  827.     To detect your video adapter you may try ~detectgraph~ declared in
  828.   ~GRAPHICS.H~. Compilers earlier than Turbo C 3.0 may have enhanced versions
  829.   of detectgraph that may return other values for a SVGA+ adapter. Unhapply
  830.   I don't have these new versions.
  831.  
  832.     mode is the same as enum ~graphics_drivers~ (declared in GRAPHICS.H) for
  833.   values 1(CGA) 2 (MCGA) 3,4,5 (EGA) and 9(VGA or better).
  834.  
  835.     crt_detect reads video hardware to detect if video is in text mode or
  836.   in graphics mode.
  837.  
  838.     crt_detect is also affected by ~crt_EVGA_addr~
  839.  
  840.     Important: I can't guarantee that crt_detect and crt_init will detect
  841.   the above CRT.H global variables correctly in a adapter other than CGA
  842.   or color VGA/SVGA.
  843.  
  844. % Return Value:
  845.     Both functions return nothing.
  846.  
  847. % Portability:
  848.     See ~appendix A~
  849.  
  850. % Hardware Compatibility:
  851.     CGA, MCGA, EGA, VGA, SVGA and newer (tested only CGA and SVGA)
  852.  
  853. % See also:
  854.     ~detectgraph~
  855.  
  856. % Example:
  857.  
  858.   Warning: Before running this example, check your video adapter type.
  859.   If your adapter is not a color VGA (or SVGA or better), replace crt_detect/
  860.   crt_init input argument by one of the following: CGA, MCGA, EGA.
  861.  
  862.  #include <CRT.H>
  863.  #include <conio.h>
  864.  
  865.  #define CGA 1
  866.  #define MCGA 2
  867.  #define EGA 3
  868.  #define VGA 9
  869.  
  870.  void main ()
  871.   {
  872.     //Messages
  873.     char *msg[2]={"Text","Graphics"};
  874.     char *msg2[2]={
  875.        "Current page base address (video_addr)",
  876.        "Value of video_addr (not changed)"};
  877.  
  878.     //Detects screen mode, number of columns, rows, etc
  879.     //If your adapter is not VGA/SVGA replace crt_init/crt_detect parameter.
  880.     //You may choose between calling crt_init or calling crt_detect,
  881.     //setcrtwin and updating crtwin_just
  882.     crt_init (VGA);  //or
  883.     //crt_detect (VGA);
  884.     //setcrtwin (-1,-1,vmode_x,vmode_y);
  885.     //crtwin_just=1;
  886.  
  887.     //Paints the screen and displays the title
  888.     fillscr ('░',0x19);
  889.     fillbar (' ',2,4,60,16,0x17);
  890.     printsj ("* * * CRT_DETECT/CRT_INIT EXAMPLE * * *",1,0x1E);
  891.  
  892.     //Displays a report after a call to crt_init
  893.     printxf (5,5,0x1f,"Current video mode (vmode_mode) = %d (%.2X)h",
  894.        vmode_mode,vmode_mode);
  895.     printxf (5,7,0x1f,"Active display page (crt_page) = %d",crt_page);
  896.     printxf (5,9,0x1f,"%s mode selected. (crt_direct = %d)",msg[crt_direct],
  897.        crt_direct);
  898.     printxf (5,11,0x1f,"%s = %Fp",msg2[crt_direct],video_addr);
  899.     printxf (5,13,0x1f,"Number of columns (vmode_x) = %d",vmode_x);
  900.     printxf (5,15,0x1f,"Number of rows (vmode_y) = %d",vmode_y);
  901.  
  902.     //Displays message to exit and pauses
  903.     printsj (" - - - Hit any key to exit - - - ",vmode_y-1,0x9e);
  904.     getch ();
  905.   }
  906.  
  907. :videomode
  908. % ▄▄▄▄▄▄▄▄▄▄▄
  909. % ▌videomode▐                          <~CRT.H~>
  910. % ▀▀▀▀▀▀▀▀▀▀▀
  911.   Changes ~vmode_x~ and ~vmode_y~ to normally used values (commonly text mode
  912.  number of rows and columns) (obsolete function)
  913.  
  914. % Declaration:
  915.     void videomode (int newmode);
  916.  
  917. % Remarks:
  918.     newmode changes global variables vmode_x and vmode_y to predefined values.
  919.   These global variables defines the number of rows and columns of current text
  920.   mode (or text mode that should be selected). The predefined values are the
  921.   most common number of rows and columns of text modes, they are listed in the
  922.   table below:
  923.  
  924.                    │  (expected text mode size)
  925.        newmode:    │  vmode_y     vmode_x
  926.   ═════════════════╪═══════════════════════════════════════════
  927.     -1 (LASTMODE)  │  (last mode values)   (default=25 X 80)
  928.     0  (BW40)      │     25   X   40
  929.     1  (C40)       │     25   X   40
  930.     2  (BW80)      │     25   X   80
  931.     3  (C80)       │     25   X   80       (default)
  932.     7  (MONO)      │     25   X   80
  933.     24             │     43   X   40
  934.     32             │     43   X   80
  935.     48             │     50   X   40
  936.     64 (C4350)     │     50   X   80
  937.  
  938.   (The values in parenthesis refer to text_modes enum defined in CONIO.H)
  939.  
  940.     It was at first designed to be used with textmode, using the same value.
  941.   textmode selects video mode and videomode updates vmode_x and vmode_y. As
  942.   we can see in the table above, videomode is not perfect, for example
  943.   (C4350) may select 50 or 43 columns in textmode, but only 50 in videomode.
  944.   With creation of crt_detect, there's no need to use videomode anymore.
  945.  
  946.   Note that: The videomode function has no effect in current text mode and
  947.   color display, it changes only vmode_x and vmode_y.
  948.  
  949.   IMPORTANT: As it is an obsolete function, it might not exist in future
  950.   versions. If it does it will probably be enhanced or have another
  951.   functionality.
  952.  
  953. % Return Value:
  954.     None.
  955.  
  956. % Hardware Compatibility:
  957.     modes 0,1,2,3,7 => CGA,EGA,VGA,SVGA,(mono?)
  958.     modes 24,32 => EGA (works with some limitations on VGA/SVGA)
  959.     modes 48,64 => VGA/SVGA (EGA?)
  960.     See also ~Appendix A~
  961.  
  962. % See also:
  963.   ~crt_detect~   ~textmode~
  964.  
  965. % Example:
  966.  
  967.  #include <CRT.H>
  968.  #include <conio.h>
  969.  
  970.  void main ()
  971.   {
  972.     textmode (3);
  973.     fillscr ('░',0x19);
  974.     prints ("Default mode: 25 rows x 80 columns",20,1,0x1f);
  975.     getch ();
  976.  
  977.     videomode (1);
  978.     fillscr ('░',0x2a);
  979.     prints ("Incorrect use of Videomode",0,0,0x2f);
  980.     prints ("25 X 40 screen size for functions",5,2,0x2f);
  981.     prints ("But in 25 X 80 text mode",10,3,0x2f);//note the interesting effect
  982.     getch ();
  983.  
  984.     textmode (1);
  985.     videomode (1);
  986.     fillscr ('░',0x2a);
  987.     prints ("Right use of Videomode",0,0,0x2f);
  988.     prints ("25 X 40 screen size for functions",5,1,0x2f);
  989.     prints ("on 25 X 40 text mode",10,3,0x2f);
  990.     //with vmode_x and vmode_y corresponding to real values, there's no problem.
  991.     getch ();
  992.  
  993.     textmode (64); //if your monitor is CGA this mode change is not effective
  994.                    //I don't know if it's dangerous to try this in
  995.                    //monitors older than EGA.
  996.  
  997.     videomode (48); //if your monitor is EGA use videomode(24) instead
  998.     fillscr ('░',0x19);
  999.     prints ("Videomode in 50 X 40 text mode",5,1,0x1f);
  1000.     getch ();
  1001.  
  1002.     textmode (3);
  1003.     textmode (C4350); //if your monitor is CGA this mode change is not effective
  1004.                       //I don't know if it's dangerous to try this in
  1005.                       //monitors older than EGA.
  1006.  
  1007.     videomode (C4350); //if your monitor is EGA use videomode(32) instead
  1008.     fillscr ('▒',0x19);
  1009.     prints ("High resolution mode (50 X 80)",25,1,0x1f);
  1010.     getch ();
  1011.  
  1012.     fillscr (' ',7);//clears the screen
  1013.     crt_gotoxy(0,0);
  1014.   }
  1015.  
  1016. :setcrtmode:getcrtmode
  1017. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1018. % ▌setcrtmode and getcrtmode▐          <~CRT.H~>
  1019. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1020.    ■ setcrtmode changes current video mode and calls getcrtmode
  1021.    ■ getcrtmode gets current video mode updating vmode_x and crt_page
  1022.  
  1023. % Declaration:
  1024.    ■ void setcrtmode (int mode);
  1025.    ■ int getcrtmode (void);
  1026.  
  1027. % Remarks:
  1028.     setcrtmode calls getcrtmode after changing video mode, which stores the
  1029.  selected video mode in ~vmode_mode~.
  1030.     getcrtmode loads vmode_x with number of columns, ~crt_page~ with current
  1031.  video page and vmode_mode with current video mode. It uses INT 10h/AH=0Fh
  1032.     getcrtmode doesn't update ~vmode_y~(screen height). To update vmode_y
  1033.  use ~crt_detect~. You may try also ~gettextinfo~.
  1034.  
  1035. % Return Value:
  1036.     ■ setcrtmode:  none
  1037.     ■ getcrtmode:  current video mode (also stored in vmode_mode);
  1038.  
  1039. % Hardware Compatibility:
  1040.     CGA,EGA,PS,VGA,SVGA and newer (tested only CGA and SVGA)
  1041.  
  1042. % See also:
  1043.     ~textmode~    ~crt_detect~    ~crt_init~
  1044.  
  1045. % Example:
  1046.  
  1047.  #include <CRT.H>
  1048.  #include <conio.h>
  1049.  #include <stdio.h>
  1050.  
  1051.  void main ()
  1052.   {
  1053.     char msg[]="\nscreen width=%d\nscreen height=%d\ncurrent video page=%d\
  1054.  \ncurrent video mode=%.2Xh\n"; //message to be displayed
  1055.     getcrtmode(); //get current video mode and updates vmode_x and crt_page
  1056.                   //doesn't update vmode_y => vmode_y might be incorrect
  1057.     printf (msg,vmode_x,vmode_y, crt_page, vmode_mode); //display message
  1058.     getch ();
  1059.     setcrtmode(1); //set video mode 1.
  1060.     printf (msg,vmode_x,vmode_y, crt_page, vmode_mode);
  1061.     getch ();
  1062.     setcrtmode(7);
  1063.     printf (msg,vmode_x,vmode_y, crt_page, vmode_mode);
  1064.     getch();
  1065.     setcrtmode(3);
  1066.     printf (msg,vmode_x,vmode_y, crt_page, vmode_mode);
  1067.     getch ();
  1068.   }
  1069.  
  1070. :setcrtpage
  1071. % ▄▄▄▄▄▄▄▄▄▄▄▄
  1072. % ▌setcrtpage▐                         <~CRT.H~>
  1073. % ▀▀▀▀▀▀▀▀▀▀▀▀
  1074.     Selects video active display page.
  1075.  
  1076. % Declaration:
  1077.     void setcrtpage (int page);
  1078.  
  1079. % Remarks:
  1080.     After selecting the active display page, setcrtpage calls ~getcrtmode~ to
  1081.  update ~vmode_x~, ~vmode_mode~ and ~crt_page~ to their actual values. After
  1082.  this setcrtpage updates ~video_addr~ to starting address of current page.
  1083.  crt_page stores the current video page.
  1084.  
  1085. % Return value:
  1086.     None.
  1087.  
  1088. % Portability:
  1089.     See ~Appendix A~.
  1090.  
  1091. % Hardware Compatibility:
  1092.     CGA,EGA,PS,VGA,SVGA (tested only in CGA/SVGA)
  1093.     May work in monochrome monitors (not tested)
  1094.     May not work in PCjunior, Tandy 1000, Corona/Cordata BIOS v4.10+
  1095.  
  1096. % See also:
  1097.     ~getcrtmode~
  1098.  
  1099. % Examples:
  1100.     ~setcrtpage example~    ~Example 4~
  1101.  
  1102. :setcrtpage example
  1103. %   setcrtpage example
  1104. %  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1105.  
  1106.  #include <stdio.h>
  1107.  #include <CRT.H>
  1108.  #include <conio.h>
  1109.  
  1110.  void main ()
  1111.   {
  1112.     int c0,a0;
  1113.     char page_cor[4]={ 0x1c, 0x1e, 0x1f, 0x1b}; //colors for each page
  1114.  
  1115.     setcrtmode (3); //changes video mode
  1116.  
  1117.   /*Here the user enters the text for each video page */
  1118.     for (c0=0;c0<4;c0++)
  1119.      {
  1120.        setcrtpage(c0); //select video page given by c0
  1121.  
  1122.        //selects background color and text color of each page according to
  1123.        //page_cor
  1124.        fillscr (' ',page_cor[c0]);
  1125.  
  1126.        //writes a message to the user reporting the current video page
  1127.        printsf (20,1,0x1f,"Current video page = %d",crt_page);
  1128.        printsf (10,2,0x1f,"Write below the text for page %d. \
  1129.  To continue hit ESC key",crt_page);
  1130.  
  1131.        //reads the text written by the user until user hits ESC key
  1132.        crt_gotoxy(0,3);
  1133.        do
  1134.         {
  1135.           a0=getch();
  1136.           if (a0==0x0d)
  1137.              putchar(0x0a);
  1138.           putchar(a0);
  1139.         }
  1140.         while(a0!=0x1b);
  1141.      }
  1142.  
  1143.   /*Here each page is displayed */
  1144.     for (c0=0;c0<4;c0++)
  1145.      {
  1146.        setcrtpage(c0);
  1147.  
  1148.        //reuses the messages written before, replacing some words
  1149.        prints ("  The text you wrote",10,2,0x1f);
  1150.        prints ("any",59,2,0x1f);
  1151.  
  1152.        getch (); //waits until user hits any key
  1153.      }
  1154.     setcrtpage(0); //Select page 0 as active page (default)
  1155.     fillscr (' ',0x07); //clears the screen
  1156.   }
  1157.  
  1158. :crt_gotoxy:crt_getxy
  1159. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1160. % ▌crt_gotoxy and crt_getxy▐           <~CRT.H~>
  1161. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1162.    ■ crt_gotoxy changes current cursor position.
  1163.    ■ crt_getxy gets current cursor position.
  1164.  
  1165. % Declaration:
  1166.     void crt_gotoxy (int x,  int y );
  1167.     int  crt_getxy  (int *x, int *y);
  1168.  
  1169. % Remarks:
  1170.     crt_gotoxy and crt_getxy works in video page selected by ~crt_page~.
  1171.     crt_gotoxy moves the cursor to position (x,y), where "x" indicates the
  1172.   column and "y" indicates the row, where (0,0) is the upper left corner. If
  1173.   argument values are incorrect, the behavior will depend on BIOS type.
  1174.     crt_getxy may return the current cursor position in two ways. The first is
  1175.   by the contents of *x pointer and *y pointer, where *x=column and *y=row.
  1176.   The second is by an integer value returned by this function, that is given
  1177.   by (row * 100h + column (DX register)). crt_getxy uses INT 10h/AH=03h.
  1178.  
  1179. % Return Value:
  1180.    ■ crt_gotoxy:   none
  1181.    ■ crt_getxy:    row*100h + column (DX register from INT 10h/AH=03h)
  1182.  
  1183. % Hardware Compatibility:
  1184.     All video adapters. (or almost all of them)
  1185.  
  1186. % See also:
  1187.     ~gotoxy~   ~wherex~   ~wherey~
  1188.  
  1189. % Example:
  1190.  
  1191.  #include <CRT.H>
  1192.  #include <conio.h>
  1193.  
  1194.  void main ()
  1195.   {
  1196.     int x, y;
  1197.     int x0, y0, z;
  1198.     //clears the screen
  1199.     fillscr (' ',0x07);
  1200.     //saves current cursor position in x, y and z.
  1201.     z=crt_getxy(&x0,&y0);
  1202.     //outputs current position
  1203.     printsf (x0%10,y0%10,0x1f,"Current cursor position = (%d,%d)",x0,y0);
  1204.     printsf (x0%10,y0%10+1,0x1f,"Value returned by crt_getxy = %.4Xh",z);
  1205.     getch ();
  1206.     //moves the cursor to a new position
  1207.     crt_gotoxy (x0%10+31,y0%20+2);
  1208.     crt_getxy(&x,&y);
  1209.     printsf (x%10,y%10+2,0x1f,"New cursor position = (%d,%d) => ",x,y);
  1210.     getch ();
  1211.     //restores initial position
  1212.     crt_gotoxy (x0,y0);
  1213.     printsf (x0%10,y0%10+3,0x1f,"Old cursor position = (%d,%d)",x0,y0);
  1214.     getch ();
  1215.   }
  1216.  
  1217.  
  1218. :getcrtchar:getcrtcolor
  1219. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1220. % ▌getcrtchar and getcrtcolor▐         <~CRT.H~>
  1221. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1222.    ■ getcrtchar gets the character from position (x,y).
  1223.    ■ getcrtcolor gets the color from position (x,y).
  1224.  
  1225. % Declaration:
  1226.    ■ int   getcrtchar  (int x, int y);
  1227.    ■ int   getcrtcolor (int x, int y);
  1228.  
  1229. % Remarks:
  1230.  
  1231.     These functions uses direct VIDEO RAM access when crt_direct==0,
  1232.   otherwise they use access via BIOS calls (INT 10h/AH=8).
  1233.     In graphics mode, crt_direct must be different than 0 (zero), and
  1234.   getcrtchar and getcrtcolor may not work properly. Documentation about
  1235.   INT 10h/AH=8 says that in graphics mode only characters drawn with
  1236.   white foreground pixels are matched by the pattern-comparison routine.
  1237.  
  1238. % Return Value:
  1239.    On success: got character and color.
  1240.    On error: random value (for example, if you gave coordinates outside the
  1241.    range of the current screen mode, or if BIOS calls fail)
  1242.  
  1243. % Examples:
  1244.     ~Example 1~
  1245.  
  1246. %   getcrtchar and getcrtcolor example:
  1247.  
  1248.  #include <CRT.H>
  1249.  #include <conio.h>
  1250.  
  1251.  void main ()
  1252.   {
  1253.     int a0,a1;
  1254.     a0=getcrtchar(0,0); //getcrtchar reads the char from position (0,0)
  1255.     a1=getcrtcolor(0,0); //getcrtcolor gets the color from position (0,0)
  1256.  
  1257.     //the character and color found at position (0,0) are displayed
  1258.     printsf(0,2,15,"Character at position (0,0)='%c' ",a0);
  1259.     printsf(0,3,15,"Color at position (0,0)=%.2Xh ",a1);
  1260.     getch ();
  1261.   }
  1262.  
  1263. :biosprintc
  1264. % ▄▄▄▄▄▄▄▄▄▄▄▄
  1265. % ▌biosprintc▐                         <~CRT.H~>
  1266. % ▀▀▀▀▀▀▀▀▀▀▀▀
  1267.     outputs a character into screen via BIOS calls.
  1268.  
  1269. % Declaration:
  1270.     void biosprintc (int chr, int x, int y, int color, int func);
  1271.  
  1272. % Remarks:
  1273.     The function biosprintc is used by other functions to access the screen
  1274.   when ~crt_direct~ != 0, but it can also be used by the programmer.
  1275.     The argument "func" defines which BIOS function will be used. The only
  1276.   accepted values (as I know) are 09h or 0Ah, different values may let to
  1277.   unpredictable and likely disastrous results.
  1278.     crt_direct has no effect over biosprintc.
  1279.     values for "func":
  1280.        09h   => outputs character with color (both in text and
  1281.                 graphics mode).
  1282.        0Ah   => Outputs character. In text mode writes only the character,
  1283.                 keeping the color of position (x,y)
  1284.                 In graphics mode draws character with color (just as when
  1285.                 func==9).
  1286.  
  1287.     The argument "func" is the value of AH register in a call to INT 10h,
  1288.   which selects the video function that must be used. Other arguments are
  1289.   similar to printc arguments.
  1290.     If attribute bit 7 is set in <256-color graphics mode, character is XOR'ed
  1291.   onto screen.
  1292.  
  1293. % Return value:
  1294.     None.
  1295.  
  1296. % Hardware Compatibility:
  1297.     All PC video adapters. (at least most of them)
  1298.  
  1299. % See also:
  1300.     ~printc~   ~printcn~   ~changecolor~
  1301.  
  1302. % Example:
  1303.  
  1304.  #include <CRT.H>
  1305.  #include <conio.h>
  1306.  
  1307.  void main ()
  1308.   {
  1309.     clrscr (); //clears the screen
  1310.     getch ();
  1311.     biosprintc ('A',2,2,0x1e,9);
  1312.        //sends character 'A' with color 1Eh (yellow with blue background)
  1313.     getch ();
  1314.     biosprintc ('B',2,3,0x1f,10);
  1315.        //sends character 'B'
  1316.        //On text mode, keeps the previous color at position. In graphics mode
  1317.        //outputs with color 1Fh
  1318.     getch ();
  1319.   }
  1320.  
  1321. :printcn:printc:changecolor
  1322. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1323. % ▌printcn, printc▐                    <~CRT.H~>
  1324. % ▌and changecolor▐
  1325. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1326.    ■ printcn outputs a character with no color onscreen.
  1327.    ■ printc  outputs a character with color onscreen.
  1328.    ■ changecolor changes the color of position (x,y).
  1329.  
  1330. % Declaration:
  1331.    ■ void  printcn     (int c, int x, int y           );
  1332.    ■ void  printc      (int c, int x, int y, int color);
  1333.    ■ void  changecolor (       int x, int y, int color);
  1334.  
  1335. % Remarks:
  1336.     printc, printcn and changecolor use video RAM access when ~crt_direct~==0,
  1337.   otherwise they use ~biosprintc~ (output via BIOS calls).
  1338.  
  1339.     With crt_direct==0 they work only in text mode and:
  1340.      - printcn outputs the character keeping the previous color.
  1341.      - printc outputs the character with color (attribute)
  1342.      - changecolor replaces the existing color (attribute) by a new one.
  1343.  
  1344.     With crt_direct!=0:
  1345.      - printcn calls biosprintc with color 0x07 and "func"=0x0a.
  1346.      - printc calls biosprintc with argument "func"=0x09.
  1347.      - changecolor gets the character from position and redraws it with a
  1348.        new color (using biosprintc).
  1349.  
  1350. % Return Value:
  1351.     none (for all them)
  1352.  
  1353. % Hardware Compatibility:
  1354.     All PC video adapters (or almost all of them)
  1355.  
  1356. % See Also:
  1357.     ~printct~   ~print...~ functions   ~printx~
  1358.  
  1359. % Examples:
  1360.     ~Example 1~
  1361.  
  1362. %   printcn, printc and changecolor example:
  1363.  
  1364.  #include <CRT.H>
  1365.  #include <conio.h>
  1366.  
  1367.  //Notice what happens at the upper left corner of the screen
  1368.  
  1369.  void main ()
  1370.   {
  1371.     fillscr (' ',0x07); //clears the screen
  1372.     getch ();
  1373.     printcn ('A',0,0); //writes character A onscreen at the upper left corner
  1374.     getch ();
  1375.     printc ('B',1,0,0x1e); //writes character B beside A character
  1376.     getch ();
  1377.     changecolor (0,0,0x21); //changes the color of A character
  1378.     getch ();
  1379.   }
  1380.  
  1381. :printct
  1382. % ▄▄▄▄▄▄▄▄▄
  1383. % ▌printct▐                            <~CRT.H~>
  1384. % ▀▀▀▀▀▀▀▀▀
  1385.     Changes the character and color of position (x,y) or keeps old character
  1386.   and/or color according to type parameter.
  1387.  
  1388. % Declaration:
  1389.     void printct(int c, int x, int y, int color, unsigned int type);
  1390.  
  1391. % Remarks:
  1392.     printct is a generalization of ~printcn~, ~printc~ and ~changecolor~. It's
  1393.   output will depend on ~printct type~ parameter.
  1394.  
  1395.     printct (c,x,y,color,1) is equivalent to printcn
  1396.     printct (c,x,y,color,2) is equivalent to changecolor
  1397.     printct (c,x,y,color,3) is equivalent to printc
  1398.  
  1399.     To use printct in graphics mode, ~crt_direct~ must be different of
  1400.   zero. To detect if video is in text or graphics mode use ~crt_detect~.
  1401.  
  1402. % Return value:
  1403.     None.
  1404.  
  1405. % See also:
  1406.     ~fillbox~
  1407.  
  1408. % Example:
  1409.  //To run this example in graphics mode, set crt_direct to 1
  1410.  
  1411.  #include <CRT.H>
  1412.  
  1413.  void main ()
  1414.   {
  1415.     fillscr ('.',LIGHTBLUE);//fills the screen with '.' and color LIGHTBLUE
  1416.  
  1417.  //printct called with char. 'A' and color 2Eh at position (8,5) with type=0
  1418.     prints ("=> type = 0",10,5,0x07);
  1419.     printct('A',8,5,0x2e,0);
  1420.  
  1421.  //printct called with char. 'A' and color 2Eh at position (8,6) with type=1
  1422.     prints ("=> type = 1",10,6,0x07);
  1423.     printct('A',8,6,0x2e,1);
  1424.  
  1425.  //printct called with char. 'A' and color 2Eh at position (8,7) with type=2
  1426.     prints ("=> type = 2",10,7,0x07);
  1427.     printct('A',8,7,0x2e,2);
  1428.  
  1429.  //printct called with char. 'A' and color 2Eh at position (8,8) with type=3
  1430.     prints ("=> type = 3",10,8,0x07);
  1431.     printct('A',8,8,0x2e,3);
  1432.   }
  1433.  
  1434. :printct type
  1435. %   type argument of printct and fillbox
  1436. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1437.  
  1438.  
  1439.  bitfields for type:
  1440.  
  1441.     ╔══╤══╤══╤══╤══╤══╤══╤══╤══╤══╤══╤══╤══╤══╦══╦══╗
  1442.     ║15│14│13│12│11│10│ 9│ 8│ 7│ 6│ 5│ 4│ 3│ 2║ 1║ 0║
  1443.     ╚══╧══╧══╧══╧══╧══╧══╧══╧══╧══╧══╧══╧══╧══╬══╬══╝
  1444.        bits 15-2 are reserved for future        │  │
  1445.     versions, although printct works with any   │  │
  1446.     value in these bits, they should be zero, to│  │
  1447.     enable compatibility with future versions   │  │
  1448.                                                 │  │
  1449.     Color control bit ──────────────────────────┘  │
  1450.        0 = printct doesn't replace color in text   │
  1451.            mode. In some graphics mode color is 7h │
  1452.            (light gray)                            │
  1453.        1 = printct replaces the color of position  │
  1454.            (x,y) by (color)                        │
  1455.                                                    │
  1456.     Text control bit ──────────────────────────────┘
  1457.        0 = printct doesn't replace character in text mode.
  1458.            In graphics mode character is read from (x,y) position
  1459.            and rewritten. (character may not be the same, due to
  1460.            failure of BIOS routine that reads character from screen
  1461.            in graphics mode)
  1462.  
  1463.  
  1464. :printsn:prints:printxy:print...
  1465. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1466. % ▌printsn, prints and printxy▐        <~CRT.H~>
  1467. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1468.    ■ printsn outputs a string into screen keeping the previous color of each
  1469.      position.
  1470.    ■ prints  outputs a string into screen with color.
  1471.    ■ printxy outputs a string into screen with color and user defined spacing
  1472.      between characters.
  1473.  
  1474. % Declaration:
  1475.    ■ void  printsn (char *s, int x, int y);
  1476.    ■ void  prints  (char *s, int x, int y, int color);
  1477.    ■ void  printxy (char *s, int x, int y, int dx, int dy, int color);
  1478.  
  1479. % Remarks:
  1480.     The start position is given by (x,y). prints and printsn outputs the
  1481.   string in horizontal, while printxy may output in any direction.
  1482.  
  1483.     prints and printxy use ~printc~ function, while printsn uses ~printcn~.
  1484.  
  1485.     In printxy, the dx and dy arguments defines the horizontal and vertical
  1486.   increments between characters, respectively. For example, if dx=-1 and dy=0,
  1487.   the string is displayed in backward direction.
  1488.  
  1489. % Return Value:
  1490.      None (all of them)
  1491.  
  1492. % Hardware Compatibility:
  1493.     Depends on ~printc~ and ~printcn~ compatibility.
  1494.  
  1495. % See also:
  1496.     ~printx~   ~printtext~   ~printsj~   ~printsjc~
  1497.     CRT.H ~print...f~ functions
  1498.  
  1499. % Examples:
  1500.     ~Example 1~
  1501.  
  1502. %   printsn, prints, and printxy example:
  1503.  
  1504.  #include <CRT.H>
  1505.  #include <conio.h>
  1506.  
  1507.  void main ()
  1508.   {
  1509.     fillscr (' ',0x07); //clears the screen
  1510.     getch ();
  1511.     printsn("PRINTSN EXAMPLE",2,0); //outputs string without replacing
  1512.        //previous color
  1513.     getch ();
  1514.     prints("PRINTS EXAMPLE",2,1,0x1e); //outputs string in yellow with a blue
  1515.        //background
  1516.     getch ();
  1517.     printxy("READ THIS -< ELPMAXE YXTNIRP",60,2,-2,0,0x1f); //outputs string
  1518.        //in backward direction. The color is white with a blue background
  1519.     getch ();
  1520.   }
  1521.  
  1522. :printx
  1523. % ▄▄▄▄▄▄▄▄
  1524. % ▌printx▐                             <~CRT.H~>
  1525. % ▀▀▀▀▀▀▀▀
  1526.     Outputs a string into screen with special options possibilities.
  1527.  
  1528. % Declaration:
  1529.     void printx (char *s, int x, int y, int color);
  1530.  
  1531. % Remarks:
  1532.     This function allows you to output a hole text with different colors and
  1533.   justifying options with a single call.
  1534.     The string (s) is a null terminated buffer that contains the text to be
  1535.   outputted and instructions character to be interpreted. In fact this function
  1536.   has it's own instruction set.
  1537.     The arguments (x,y,color) loads only the initial values, that can be
  1538.   changed by some instructions inside the string.
  1539.  
  1540.   The printx's "instruction set" is: (sorted by "opcode")
  1541.     (05)h     => Outputs the third byte with the color defined by the second
  1542.                  byte.
  1543.     (ENQ)          Format => "... \5<color><character(3rd byte)> ..."
  1544.  
  1545.     (06)h     => Changes current color to color defined by next byte.
  1546.     (ACK)          Format => "... \6<color> ..."
  1547.  
  1548.     (07)h     => Emits a "beep" via DOS call.
  1549.     (BELL)         Format => "... \a ..." OR "... \7 ..."
  1550.  
  1551.     (08)h     => Non destructive backspace. If current position is left side,
  1552.     (BKSPACE)    returns to the end of upper line (row).
  1553.                    Format => "... \b ..." OR "... \10 ..."
  1554.  
  1555.     (09)h     => Non destructive Tab (default tab size = 8)
  1556.     (TAB)          Format => "... \t ..." OR "... \11 ..."
  1557.  
  1558.     (0A)h     => New line and "carriage return" to taboffset value. (default==0)
  1559.     (NF)         It has the same effect of \n in ...printf functions,
  1560.                  if taboffset==0. (taboffset is an internal variable)
  1561.                    Format => "... \n ..." OR "... \12 ..."
  1562.  
  1563.     (0B)h     => New line (character (0A)h function in printer)
  1564.     (VT)           Format => "... \v ..." OR "... \13 ..."
  1565.  
  1566.     (0C)h     => Goes to upper left corner (position (0,0)).
  1567.     (FF)           Format => "... \f ..." OR "... \14 ..."
  1568.  
  1569.     (0D)h     => Returns to left size with offset defined by (taboffset)
  1570.     (CR)         (default for taboffset == 0).
  1571.                    Format => "... \r ..." OR "... \15 ..."
  1572.  
  1573.     (0E)h     => Changes x value. (column where next character will be
  1574.                  outputted)
  1575.     (SO)           Format => "... \16<new column position> ..."
  1576.  
  1577.     (0F)h     => Changes y value. (row where next character will be outputted)
  1578.     (SI)           Format => "... \17<new row position> ..."
  1579.  
  1580.     (10)h     => Changes tab size (default size = 8).
  1581.                    Format => "... \20<new tab size> ..."
  1582.  
  1583.     (11)h     => Changes taboffset value (offset for TAB) (default = 0).
  1584.                    Format => "... \21<taboffset> ..."
  1585.  
  1586.     (12)h     => Increments x value (column).
  1587.                    Format => "... \22 ..."
  1588.  
  1589.     (13)h     => Decrements y value (row).
  1590.                    Format => "... \23 ..."
  1591.  
  1592.     (14)h     => Pauses until a key is available from keyboard, checking
  1593.                  ^C/^BREAK.
  1594.                   Uses DOS function INT 21h/AH=08h
  1595.                    Format => "... \24 ..."
  1596.  
  1597.     (15)h     => Pauses until a key is available from keyboard. ^C/^BREAK are
  1598.                  not checked.
  1599.                   Uses DOS function INT 21h/AH=07h
  1600.                    Format => "... \25 ..."
  1601.  
  1602.     (1B)h     => Allows to output special characters ("opcodes" as characters)
  1603.     (ESC)          Format => "... \33<char.> ..."
  1604.  
  1605.  
  1606.   IMPORTANT: Do not left a instruct character that requires any complement
  1607.   (instructions 05h, 06h, 0Eh, 0Fh 10h 11h 1Bh) being the last of the string,
  1608.   the reason is that printx will confuse the null terminating character (\0)
  1609.   (automatically appended at the end of each string by the compiler) as
  1610.   a complement. As result printx will write and process beyond the end of
  1611.   the string (if you are not lucky it will continue far beyond and you will
  1612.   need to wait for hours until it stops).
  1613.  
  1614. % Return Value:
  1615.     None.
  1616.  
  1617. % Portability:
  1618.     Requires DOS or DOS compatible O.S (such as WINDOWS, WINDOWS 95/98)
  1619.     See also ~appendix A~.
  1620.  
  1621. % Hardware Compatibility:
  1622.     Will depend most of function ~printc~.
  1623.  
  1624. % See Also:
  1625.     ~prints~  ~printxy~   ~printtext~   ~printsj~   ~printsjc~
  1626.     CRT.H ~print...f~ functions.
  1627.  
  1628. % Example:
  1629.     ~printx example~
  1630.  
  1631. :printx example
  1632. %   printx example
  1633. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1634.  
  1635.  #include <CRT.H>
  1636.  #include <conio.h>
  1637.  
  1638.  void main ()
  1639.   {
  1640.  //THIS IS THE STRING CONTAINING THE TEXT TO BE OUTPUTTED. THE SPECIAL EFFECTS
  1641.  //ARE OBTAINED VIA SPECIAL CHARACTERS (IN FACT PRINTX "OPCODES") For example
  1642.  //\n is an "instruction opcode" with the same function as \n in printf
  1643.     int a0;
  1644.     char sentence []= //\24 is the pause character, byte or "opcode"
  1645.  "* * * printx example * * *\
  1646.  \16\5\17\4\6\36\
  1647.  Example of printx function.\
  1648.  \n\Outputting (sentence) string contents\n\
  1649.  Hit any key to continue\24\
  1650.  \
  1651.  \6\x1f new color \24\
  1652.  \
  1653.  temporary color at \"\5\x1c\C\"\n\24\
  1654.  \
  1655.  BEEP\a\a\a\24\
  1656.  \
  1657.  \b\b\b\bBKSPACE 4 times\24\
  1658.  \
  1659.  \t\tTabulation\24\
  1660.  \
  1661.  \n\n\nNew line and return to begin of line\24\
  1662.  \
  1663.  \v\New line without returning to it's begin\24\
  1664.  \
  1665.  \rreturn to begin of line\24\
  1666.  \
  1667.  \fgoes to upper left corner\24\
  1668.  \
  1669.  \16\30\17\20Moves to position (24,16) => (30,20)octal\n\24\
  1670.  \
  1671.  \
  1672.  Tab size = 3:\20\3\na\ta\ta\ta\ta\n\24\
  1673.  \
  1674.  Tab Offset = 1:\21\1\na\ta\ta\ta\ta\n\n\24\
  1675.  \
  1676.  \33\5 Special character.\24\
  1677.  Pauses checking ^C/^BREAK.\24\
  1678.  Pauses without checking ^C/^BREAK.\25\
  1679.  \
  1680.  \
  1681.  \16\20\17\27\6\x9e - - - THE END - HIT ANY KEY TO RETURN - - -\25\
  1682.  ";//here ends the string.
  1683.  
  1684.  //ONLY THIS IS THE PROGRAM ITSELF
  1685.  
  1686.     fillscr ('░',0x19); //fills the screen with character '░' and color 0x19
  1687.  
  1688.   //all that text is outputted via this function! This function does almost
  1689.     printx (sentence,27,1,0x1f); //everything in this program!
  1690.  
  1691.   /*This displays the contents of sentence string with no formatting.*/
  1692.  
  1693.     fillscr (' ',7); //clears the screen
  1694.     prints ("(sentence) string contents with no formatting :",16,0,0x0f);
  1695.     a0=printtext(sentence,0,2,0x07); //displays the text in raw format
  1696.     printsf (0,11,0x0e,"(sentence) string size = %d bytes",a0);
  1697.        //a0=number of bytes in sentence
  1698.     getch ();
  1699.   }
  1700.  
  1701. :printtext
  1702. % ▄▄▄▄▄▄▄▄▄▄▄
  1703. % ▌printtext▐                          <~CRT.H~>
  1704. % ▀▀▀▀▀▀▀▀▀▀▀
  1705.     Writes a string inside a box continuing in the next line if text doesn't
  1706.   fit in one line.
  1707.  
  1708. % Declaration:
  1709.     int printtext (char *s, int x, int y, int color);
  1710.  
  1711. % Remarks:
  1712.     printtext writes inside the box defined by ~crtwin_dta~ struct. It starts
  1713.   writing at position (x,y) in relation to (crtwin_dta.left+1,crtwin_dta.top+1)
  1714.   with color defined by color. When reaching the end of line (column
  1715.   crtwin_dta.right-1) it continues in the next line (starting at column
  1716.   crtwin_dta.left+1). When it reaches the end of the last line of the box
  1717.   (position (crtwin_dta.right-1,crtwin_bottom-1)) it stops.
  1718.     If one (or both) of the coordinates is negative, the call to printtext is
  1719.   ignored.
  1720.  
  1721. % Return value:
  1722.     number of bytes written.
  1723.  
  1724. % Portability:
  1725.     See ~Appendix A~.
  1726.  
  1727. % Hardware Compatibility:
  1728.     Depends on ~printc~
  1729.  
  1730. % See also:
  1731.     ~prints~   ~printx~   ~printsj~    ~printsjc~
  1732.     CRT.H ~print...f~ functions
  1733.  
  1734. % Examples:
  1735.  
  1736.  ~printtext example~   ~printx example~    ~Example 3~
  1737.  
  1738. :printtext example
  1739. %   printtext example
  1740. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1741.  #include <CRT.H>
  1742.  #include <conio.h>
  1743.  
  1744.  void main ()
  1745.   {
  1746.     fillscr (' ',0x07);
  1747.     printtext (
  1748.  "This is an example of printtext function. Notice that printtext continues in\
  1749.   the next line if text doesn't fit in one line. Text is outputted inside text\
  1750.   window defined by crtwin_dta",10,1,0x1f);
  1751.     getch();
  1752.   }
  1753.  
  1754. :printsj:printsjc
  1755. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1756. % ▌printsj and printsjc▐               <~CRT.H~>
  1757. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1758.     ■prinstj writes a string inside the current text box defined by
  1759.   ~crtwin_dta~ struct with justification defined by ~crtwin_just~.
  1760.     ■printsjc is a enhanced version of printsj that allows color change
  1761.   inside the text to be outputted.
  1762.  
  1763. % Declaration:
  1764.     ■ void printsj  (char *s, int y, int color);
  1765.     ■ void printsjc (char *s, int y, int color);
  1766.  
  1767. % Remarks:
  1768.  
  1769.     printsj and printsjc write the null terminated string (s) with color
  1770.   (color) (y+1) lines below the line defined by (crtwin_dta.top)
  1771.     If coordinates given by crtwin_dta are invalid, the call to printsj or
  1772.   printsjc is ignored.
  1773.     for (y) values greater than the box height or smaller than zero, y assumes
  1774.   any value between 0 and the box height or any of both values.
  1775.     if crtwin_just is not 0 nor 1 nor 2, the call to printsj or printsjc is
  1776.   ignored. (That means printsj or printsjc returns without doing anything.)
  1777.  
  1778.     printsjc allows you to output a hole text with different colors with a
  1779.   single call. The argument color gives the beginning color of the text.
  1780.     The string (s) is a null terminated string that contains the text to be
  1781.   outputted and "instructions" character to be interpreted. These characters
  1782.   constitute printsjc "instruction set" (kind of a subset of printx
  1783.   instruction set).
  1784.     The arguments (x,y,color) loads only the initial values, that can be
  1785.   changed by some instructions inside the string.
  1786.  
  1787.   The printsjc's "instruction set" is: (sorted by "opcode")
  1788.     (05)h     => Outputs the third byte with the color defined by the second
  1789.                  byte.
  1790.     (ENQ)          Format => "... \5<color><character(3rd byte)> ..."
  1791.  
  1792.     (06)h     => Changes current color to color defined by next byte.
  1793.     (ACK)          Format => "... \6<color> ..."
  1794.  
  1795.     (1B)h     => Allows to output special characters ("opcodes" as characters)
  1796.     (ESC)          Format => "... \33<char.> ..."
  1797.  
  1798.  
  1799.   IMPORTANT: Do not left a instruct character being the last of the string,
  1800.   the reason is that printsjc will confuse the null terminating character (\0)
  1801.   (automatically appended at the end of each string by the compiler) as a
  1802.   complement. As result printsjc will write and process beyond the end of the
  1803.   string (if you are not lucky it will continue far beyond and you will need
  1804.   to wait for some minutes until it stops (the screen will become a mess)).
  1805.  
  1806.     printsjc uses special color "instruction" characters to change the
  1807.   color inside the text.
  1808.  
  1809.   Both functions use function ~printc~.
  1810.  
  1811. % Return Value:
  1812.     ■ printsj:  none
  1813.     ■ printsjc: none
  1814.  
  1815. % Portability:
  1816.     See ~appendix A~.
  1817.  
  1818. % Hardware Compatibility:
  1819.     Depends on ~printc~ compatibility.
  1820.  
  1821. % See Also:
  1822.     ~printsn~   ~prints~   ~printxy~   ~printx~   ~printtext~
  1823.     CRT.H ~print...f~ functions
  1824.  
  1825. % Examples:
  1826.     ~printsj example~   ~printsjc example~   ~Example 3~
  1827.  
  1828. :printsj example
  1829. %   printsj example
  1830. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1831.  
  1832.  #include <conio.h>
  1833.  #include <CRT.H>
  1834.  
  1835.  void main ()
  1836.   {
  1837.     fillscr (' ',0x17);
  1838.     printsj("* * * PRINTSJ EXAMPLE * * *",1,0x1f);
  1839.  
  1840.  //LEFT JUSTIFIED TEXT
  1841.     crtwin_just=0;
  1842.     printsj("LEFT JUSTIFIED TEXT => crtwin_just=0",4,0x1e);
  1843.  
  1844.  //CENTER JUSTIFIED TEXT
  1845.     crtwin_just=1;
  1846.     printsj("CENTER JUSTIFIED TEXT => crtwin_just=1",6,0x1a);
  1847.  
  1848.  //RIGHT JUSTIFIED TEXT
  1849.     crtwin_just=2;
  1850.     printsj("RIGHT JUSTIFIED TEXT => crtwin_just=2",8,0x1b);
  1851.     getch ();
  1852.   }
  1853.  
  1854. :printsjc example
  1855. %   printsjc example
  1856. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1857.  
  1858.  #include <CRT.H>
  1859.  #include <conio.h>
  1860.  
  1861.  void main ()
  1862.   {
  1863.     fillscr (' ',0x17);
  1864.     printsjc("* * * PRINTSJC EXAMPLE * * *",1,0x1f);
  1865.  
  1866.  //LEFT JUSTIFIED TEXT
  1867.     crtwin_just=0;
  1868.     printsjc("LEFT JUSTIFIED TEXT => crtwin_just=0",4,0x1e);
  1869.  
  1870.  //CENTER JUSTIFIED TEXT
  1871.     crtwin_just=1;
  1872.     printsjc("CENTER JUSTIFIED TEXT => crtwin_just=1",6,0x1a);
  1873.  
  1874.  //RIGHT JUSTIFIED TEXT
  1875.     crtwin_just=2;
  1876.     printsjc("RIGHT JUSTIFIED TEXT => crtwin_just=2",8,0x1b);
  1877.  
  1878.  //COLOR INSTRUCTIONS
  1879.     crtwin_just=1;
  1880.     printsjc("EACH\6\x1e WORD\6\x1f WITH \5\x1a\x41 \6\x1b\x44IFERENT\6\x19 \
  1881.  COLOR\6\x1d !!!",11,0x1c);
  1882.     printsjc("EXAMPLE OF \"INST.\" CHARS. New color at '\5\x1b\x43'. \
  1883.  New \6\x1e\x63olor. Special chars => \x1b\5 \x1b\6 \x1b\x1b",14,0x1f);
  1884.     getch ();
  1885.   }
  1886.  
  1887. :printsnf:printsf:printxyf:printxf:printtextf:printsjf:printsjcf:print...f
  1888. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  1889. % ▌CRT.H print...f functions▐          <~CRT.H~>
  1890. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  1891.    ■ printsnf   sends formatted output to screen via printsn.
  1892.    ■ printsf    sends formatted output to screen via prints.
  1893.    ■ printxyf   sends formatted output to screen via printxy.
  1894.    ■ printxf    sends formatted output to screen via printx.
  1895.    ■ printtext  sends formatted output to screen via printtext.
  1896.    ■ printsjf   sends formatted output to screen via printsj.
  1897.    ■ printsjcf  sends formatted output to screen via printsjc.
  1898.  
  1899. % Declaration:
  1900.    ■ int  printsnf    (int x, int y,                            char *fmt,... );
  1901.    ■ int  printsf     (int x, int y,                 int color, char *fmt,... );
  1902.    ■ int  printxyf    (int x, int y, int dx, int dy, int color, char *fmt,... );
  1903.    ■ int  printxf     (int x, int y,                 int color, char *fmt,... );
  1904.    ■ int  printtextf  (int x, int y,                 int color, char *fmt,... );
  1905.    ■ int  printsjf    (       int y,                 int color, char *fmt,... );
  1906.    ■ int  printsjcf   (       int y,                 int color, char *fmt,... );
  1907.  
  1908. % Remarks:
  1909.     These functions uses ~vsprintf~ to create the formatted string to be
  1910.     displayed.
  1911.     The formatted string mustn't exceed the internal buffer size of these
  1912.     function. If the buffer is exceeded, unpredictable and likely disastrous
  1913.     results may occur. (see table below):
  1914.  
  1915.      Functions │ Internal Buffer size
  1916.     ═══════════╪══════════════════════
  1917.      printsnf  │ 256 bytes
  1918.      printsf   │ 256 bytes
  1919.      printxyf  │ 256 bytes
  1920.      printxf   │ 4096 bytes
  1921.      printxtext│ 4096 bytes
  1922.      printsjf  │ 256 bytes
  1923.      printsjcf │ 256 bytes
  1924.  
  1925.     For further information see ...~printf~ functions
  1926.  
  1927. % Return Value:
  1928.     ■ On success, the print...f functions return the number of bytes outputted
  1929.        by vsprintf in the internal string.
  1930.     ■ On error, these functions return EOF
  1931.  
  1932. % Portability:
  1933.     It will depend on vsprintf and print... (CRT.H) functions portability.
  1934.     See also ~Appendix A~
  1935.  
  1936. % See Also:
  1937.    vsprintf     CRT.H      va_arg       va_end   va_start
  1938.  
  1939.   print...f example:
  1940.  
  1941.     The print...f functions declared in CRT.H are used in a very similar manner
  1942.  as printf is used, except that they output the formatted string using print...
  1943.  functions declared in CRT.H. For example:
  1944.     char s[4096];
  1945.     .
  1946.     .
  1947.     .
  1948.     sprintf(s,fmt,...);
  1949.     printx(s,x,y,color);
  1950.  
  1951.  is equivalent to:
  1952.     .
  1953.     .
  1954.     .
  1955.     printxf(x,y,color,fmt,...);
  1956.  
  1957. % Example:
  1958.  
  1959.  #include <CRT.H>
  1960.  #include <conio.h>
  1961.  
  1962.  void main ()
  1963.   {
  1964.     int c0=8, c1=35, c2, c3, c4, c5, c6,c7;
  1965.     fillscr ('░',0x19);
  1966.     c2=printsnf(10,0,"%d * %d = %d",c0,c1,c0*c1);
  1967.     getch();
  1968.     c3=printsf(10,1,0x1f,"%d / %d = %d and %d %c %d = %d",c1,c0,c1/c0,c1,'%',
  1969.        c0,c1%c0);
  1970.     getch();
  1971.     c4=printxyf(20,3,2,0,0x1f,"c1='%c'=%d=%xh",c1,c1,c1);
  1972.     getch ();
  1973.     setcrtwin(12,8,60,16);
  1974.     moldurad(12,8,60,16,0x1e);
  1975.     fillbar (' ',13,9,59,15,0x1f);
  1976.     c5=printsjf(1,0x1f,"Current text box is (%d,%d),(%d,%d)",
  1977.        crtwin_dta.left,crtwin_dta.top,crtwin_dta.right,crtwin_dta.bottom);
  1978.     getch ();
  1979.     c6=printsjcf(2,0x1f,"Selecting \6%ccolor given by crtwin_dta.top",
  1980.        crtwin_dta.top);
  1981.     getch ();
  1982.     c7=printtextf (2,4,0x1f,"Printtextf example => crtwin_dta.bottom=%d \
  1983.  crtwin_dta.right=%d",crtwin_dta.bottom,crtwin_dta.right);
  1984.     getch ();
  1985.     printxf (0,18,0x1e,"printsnf returned %d\tprintsf  returned %d\
  1986.  \nprintxyf returned %d\tprintsjf returned %d\tprintsjcf returned %d\
  1987.  \nprinttext returned %d%c",c2,c3,c4,c5,c6,c7,0x15);
  1988.     // 0x15=='\x15' is pause "opcode" in printx (see printx)
  1989.   }
  1990.  
  1991.  
  1992. :fillscr
  1993. % ▄▄▄▄▄▄▄▄▄
  1994. % ▌fillscr▐                            <~CRT.H~>
  1995. % ▀▀▀▀▀▀▀▀▀
  1996.     Fills the screen with character "c" and color "color".
  1997.  
  1998. % Declaration:
  1999.     void  fillscr (int c, int color);
  2000.  
  2001. % Remarks:
  2002.     As printc... functions the fillscr function uses only the memory area
  2003.   delimited by ~video_addr~, ~vmode_x~ and ~vmode_y~. For a properly work,
  2004.   vmode_x and vmode_y must be equal to actual number of columns and rows of
  2005.   current text mode, if it's not you may obtain interesting effects. It's not
  2006.   advisable to set vmode_x and vmode_y to higher values than 256 . The reason
  2007.   is that you may destroy important data stored above C800:0000h used by
  2008.   programs stored at high UMB's, when using fillscr. (Anyway I can't be liable
  2009.   for any sillyness you might do. So be careful)
  2010.  
  2011.     If ~crt_direct~==0 it access directly the video RAM, otherwise
  2012.   (crtdirect!=0) the access to video is done via biosprintc
  2013.   (no direct memory handling).
  2014.  
  2015. % Return Value:
  2016.     None.
  2017.  
  2018. % Portability:
  2019.     See ~Appendix A~.
  2020.  
  2021. % Hardware Compatibility:
  2022.     The same of ~printc~ function.
  2023.  
  2024. % See Also:
  2025.     ~fillbar~   ~barcolor~   ~fillbox~
  2026.  
  2027. % Example:
  2028.  
  2029.  #include <CRT.H>
  2030.  #include <conio.h>
  2031.  
  2032.  //Example for fillscr function
  2033.  //by Márcio Afonso Arimura Fialho
  2034.  
  2035.  void main ()
  2036.   {
  2037.     getch (); //shows the initial screen drawing.
  2038.     fillscr ('░',0x19); //fills the screen with character '░' and color 19h
  2039.                          //(light blue with a blue background)
  2040.     getch ();
  2041.     fillscr ('A',0x2e); //fills the screen with character 'A' and color 17h
  2042.                          //(yellow with a green background)
  2043.     getch ();
  2044.     fillscr ('░',0x9b); //fills the screen with character '░' and color 9Bh
  2045.                          //(blinking light cyan with a blue background)
  2046.     getch ();
  2047.     fillscr (' ',7); //clears the screen
  2048.   }
  2049.  
  2050. :barcolor
  2051. % ▄▄▄▄▄▄▄▄▄▄
  2052. % ▌barcolor▐                           <~CRT.H~>
  2053. % ▀▀▀▀▀▀▀▀▀▀
  2054.     Replaces the color of a text window to color (color)
  2055.  
  2056. % Declaration:
  2057.     void barcolor (int xi, int yi, int xf, int yf, int color);
  2058.  
  2059. % Remarks:
  2060.     xi,yi are the upper left corner co-ordinates.
  2061.     xf,yf are the lower right corner co-ordinates.
  2062.     xi,yi,xf,yf can be also understood as the left, top, right, bottom sides
  2063.   co-ordinates of the window, respectively.
  2064.  
  2065.     This function has no relationship with ~window~ function.
  2066.  
  2067.   Uses function ~changecolor~.
  2068.  
  2069. % Return Value:
  2070.     None.
  2071.  
  2072. % Portability:
  2073.     See ~Appendix A~.
  2074.  
  2075. % Hardware Compatibility:
  2076.     Depends on ~changecolor~ compatibility.
  2077.  
  2078. % See also:
  2079.     ~fillscr~     ~fillbar~     ~fillbox~
  2080.  
  2081. % Example:
  2082.  
  2083.  #include <CRT.H>
  2084.  #include <conio.h>
  2085.  
  2086.  void main ()
  2087.   {
  2088.     textmode (3);
  2089.     fillscr (' ',7);
  2090.     prints ("The color inside the box will change.",10,8,0x0f);
  2091.     moldura (20,10,40,16,0x07);
  2092.     fillbar ('A',21,11,39,15,0x07);
  2093.     getch ();
  2094.     prints ("has changed!",35,8,0x0f);
  2095.     barcolor (21,11,39,15,0x1e);
  2096.     getch ();
  2097.   }
  2098.  
  2099.  
  2100. :fillbar:fillbarw
  2101. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2102. % ▌fillbar and fillbarw▐               <~CRT.H~>
  2103. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2104.     ■ fillbar fills a text window with the character "c" and color "color".
  2105.     ■ fillbarw fills a text window given by crtwin_dta with character "c" and
  2106.       color "color".
  2107.  
  2108. % Declaration:
  2109.     ■ void fillbar (int c, int xi, int yi, int xf, int yf, int color);
  2110.     ■ void fillbarw (int c, int color);
  2111.  
  2112. % Remarks:
  2113.     xi,yi are the upper left corner co-ordinates.
  2114.     xf,yf are the lower right corner co-ordinates.
  2115.     xi,yi,xf,yf can be also understood as the left, top, right, bottom sides
  2116.   co-ordinates of the window, respectively.
  2117.  
  2118.     fillbarw calls fillbar with:
  2119.        xi=crtwin_dta.left+1;   yi=crtwin_dta.top+1;
  2120.        xf=crtwin_dta.right-1;  yf=crtwin_dta.bottom-1;
  2121.  
  2122.     These functions have no relationship with ~window~ function.
  2123.  
  2124.   Use function ~printc~.
  2125.  
  2126. % Return Value: none.
  2127.  
  2128. % Portability:
  2129.     See ~Appendix A~.
  2130.  
  2131. % Hardware Compatibility:
  2132.     Depends on printc compatibility.
  2133.  
  2134. % See also:
  2135.     ~fillscr~     ~barcolor~     ~crtwin_dta~
  2136.  
  2137. % Examples:
  2138.     ~fillbar example~     ~fillbarw example~     ~Example 2~
  2139.  
  2140. :fillbar example
  2141. %   fillbar example
  2142. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2143.  
  2144.  #include <CRT.H>
  2145.  #include <conio.h>
  2146.  
  2147.  void main ()
  2148.   {
  2149.     textmode (3);
  2150.     fillscr (' ',7);
  2151.     prints ("There's a box:",10,8,0x0f);
  2152.     moldura (20,10,40,16,0x07);
  2153.     getch ();
  2154.     fillbar ('A',21,11,39,15,0x1e);
  2155.     prints ("That has been filled up by fillbar",10,18,0x0f);
  2156.     getch ();
  2157.   }
  2158.  
  2159. :fillbox:fillboxw
  2160. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2161. % ▌fillbox and fillboxw▐               <~CRT.H~>
  2162. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2163.     ■ fillbox replaces the characters and colors of a text window or keeps old
  2164.       characters and/or colors according to type parameter.
  2165.     ■ fillboxw is similar to fillbox, but text window coordinates are given by
  2166.       ~crtwin_dta~.
  2167.  
  2168. % Declaration:
  2169.     ■ void fillbox  (int c, int xi, int yi, int xf, int yf,int color,int func);
  2170.     ■ void fillboxw (int c, int color, int func);
  2171.  
  2172. % Remarks:
  2173.     c is the character, color is the character color or attribute.
  2174.     xi,yi are the upper left corner co-ordinates.
  2175.     xf,yf are the lower right corner co-ordinates.
  2176.     xi,yi,xf,yf can be also understood as the left, top, right, bottom sides
  2177.   co-ordinates of the window, respectively.
  2178.  
  2179.     fillbox is a generalization of fillbar and barcolor functions. It's output
  2180.   will depend on func argument, which has the same functionality of
  2181.   ~printct type~ argument.
  2182.  
  2183.     fillboxw calls fillbox with:
  2184.        xi=crtwin_dta.left+1;   yi=crtwin_dta.top+1;
  2185.        xf=crtwin_dta.right-1;  yf=crtwin_dta.bottom-1;
  2186.  
  2187.     fillbox and fillboxw have no relationship with ~window~ function.
  2188.  
  2189.     fillbox uses function ~printct~.
  2190.     fillboxw uses function fillbox.
  2191.  
  2192. % Return Value: none.
  2193.  
  2194. % See Also:
  2195.     ~fillscr~     ~fillbar~     ~barcolor~
  2196.  
  2197. % Examples:
  2198.     ~fillbox example~   ~fillboxw example~
  2199.  
  2200. :fillbox example
  2201. %   fillbox example
  2202. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2203.  
  2204.  #include <CRT.H>
  2205.  
  2206.  void main ()
  2207.   {
  2208.  
  2209.     fillscr ('.',0x09);//fills the screen with character '.' and color 09h
  2210.                        //(light blue with black background)
  2211.  
  2212.  //fillbox called with character 'A' and color 2Eh with type=0
  2213.     prints ("fillbox called with type = 0",7,3,0x07);
  2214.     fillbox ('A',10,5,30,10,0x2e,0);
  2215.  
  2216.  //fillbox called with character 'A' and color 2Eh with type=1
  2217.     prints ("fillbox called with type = 1",47,3,0x07);
  2218.     fillbox ('A',50,5,70,10,0x2e,1);
  2219.  
  2220.  //fillbox called with character 'A' and color 2Eh with type=2
  2221.     prints ("fillbox called with type = 2",7,13,0x07);
  2222.     fillbox ('A',10,15,30,20,0x2e,2);
  2223.  
  2224.  //fillbox called with character 'A' and color 2Eh with type=3
  2225.     prints ("fillbox called with type = 3",47,13,0x07);
  2226.     fillbox ('A',50,15,70,20,0x2e,3);
  2227.   }
  2228.  
  2229.  
  2230. :fillboxw example
  2231. %   fillboxw example
  2232. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2233.  
  2234.  #include <CRT.H>
  2235.  #include <conio.h>
  2236.  
  2237.  //This example draws a text box filled with character '.' and color 19h
  2238.  //(light blue with blue background), and them calls fillboxw.
  2239.  //To test this example in other video modes than 80x25, use crt_detect(X)
  2240.  //where X is your video adapter (1=CGA,2=MCGA,3=EGA,9=VGA/SVGA).
  2241.  
  2242.  void main ()
  2243.   {
  2244.     int c0;
  2245.  
  2246.     //crt_detect (X);
  2247.     fillscr ('░',0x19); //fills the screen
  2248.     setcrtwin (20,7,60,17); //change text box/window coordinates
  2249.     molduradw (0x1f); //draws the text box border
  2250.  
  2251.     for (c0=0;c0<4;c0++)
  2252.      {
  2253.       //displays current type value and draws the box
  2254.        printsf (21,5,0x1e,"Before a call to fillbox with type = %d",c0);
  2255.        fillbarw ('.',0x19);
  2256.        getch ();
  2257.       //notice what fillboxw does according to type value
  2258.        prints (" After",21,5,0x1e); //fixes the message displayed on screen
  2259.        fillboxw ('A',0x1e,c0);
  2260.        getch ();
  2261.      }
  2262.   }
  2263.  
  2264. :crtframe:crtframew
  2265. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2266. % ▌crtframe and crtframew▐             <~CRT.H~>
  2267. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2268.     ■ crtframe draws the border of a text box (frame) with selectable or user
  2269.   defined outline.
  2270.     ■ crtframew is similar to crtframe, but uses box coordinates given by
  2271.   crtwin_dta.
  2272.  
  2273. % Declaration:
  2274.     ■ void crtframe (int xi, int yi, int xf, int yf, int color,
  2275.       unsigned int type);
  2276.     ■ void crtframew (int color, unsigned int type);
  2277.  
  2278. % Remarks:
  2279.     (xi,yi) is the upper left corner of the box.
  2280.     (xf,yf) is the lower right corner of the box.
  2281.  
  2282.     The frame goes from (xi,yi) to (xf,yf).
  2283.     For a better understanding, xi,yi,xf,yf can be understood as the left, top,
  2284.   right, bottom sides coordinates of the frame, respectively.
  2285.     The "color" argument is the color which the border of the text box will be
  2286.   drawn.
  2287.     The "type" argument selects which outline type will be used. There are
  2288.   three predefined types, and a user defined type, that can be defined if
  2289.   type is greater than 255 (FFh).
  2290.     The predefined types are:
  2291.        type = 0 => text box with single outline. (moldura macro)
  2292.        type = 1 => text box with double outline. (moldurad macro)
  2293.        type = 2 => text box with bold outline.
  2294.  
  2295.     The user defined type can be selected either if type==3 or if type is
  2296.   greater than 255 or smaller than 0.
  2297.     If type==3 it draws the border with current user defined character, without
  2298.        replacing it. (default='█'= DBh)
  2299.     If type>=100h it replaces the current user defined character and draws the
  2300.        border with this new character. This character is obtained from the
  2301.        remainder of "type" divided by 100h (new character=type%256) (the 8
  2302.        least significant bits of "type").
  2303.     "type" values greater than 3 or smaller than 256 are reserved for future
  2304.     versions. If type is inside this interval, the call to crtframe will be
  2305.     ignored.
  2306.     The table below summarizes the frame types according to type argument:
  2307.  
  2308.         type  │~crtframe_mat~ │  frame
  2309.        value  │ characters  │  type
  2310.    ───────────┼─────────────┼─────────────
  2311.          0    │ 0  thru 7   │ pre-defined
  2312.          1    │ 8  thru 15  │ pre-defined
  2313.          2    │ 16 thru 23  │ pre-defined
  2314.          3    │ 24 thru 31  │ user defined (default = '█')
  2315.     3<type<256│    <none>   │ none (reserved for future versions)
  2316.         >256  │ 24 thru 31  │ least 8 significant bits of type/
  2317.               │             │ redefines user defined outline
  2318.  
  2319.  
  2320.     crtframe uses crtframe_mat buffer to draw the frames, so if you want
  2321.   redefine pre-defined frames, remove from CRT.H the const directive in front
  2322.   of crtframe_mat declaration. This will allow you to edit this buffer. Note
  2323.   that characters 24 thru 31 (the number refers to it's index in on
  2324.   crtframe_mat) are changed when crtframe is called with type greater than 255,
  2325.   and are all the same.
  2326.  
  2327.     crtframew calls crtframe with (xi,yi)=(crtwin_dta.left,crtwin_dta.top)
  2328.   and (xf,yf)=(crtwin_dta.right,crtwin_dta.bottom).
  2329.  
  2330.   If you wish you may use these crtframe and crtframew macros:
  2331.       ~moldura~         ~molduraw~
  2332.       ~moldurad~        ~molduradw~
  2333.  
  2334.   They use function ~printc~.
  2335.  
  2336. % Return Value:
  2337.     None. (for both functions)
  2338.  
  2339. % Portability:
  2340.     See ~Appendix A~
  2341.  
  2342. % See Also:
  2343.     ~mkline~
  2344.  
  2345. % Examples:
  2346.     ~crtframe example~      ~crtframew example~       ~Example 2~
  2347.  
  2348. :crtframe example
  2349. %   crtframe example
  2350. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2351.  
  2352.  #include <CRT.H>
  2353.  #include <conio.h>
  2354.  
  2355.  void main ()
  2356.   {
  2357.     fillscr (' ',0x07); //clears the screen
  2358.     printsj ("- - - Hit any key to see the examples - - -",24,0x8e);
  2359.     getch ();
  2360.  
  2361.   //Draws a text frame with single outline
  2362.     prints ("Type = 0",6,3,0x1f); //message
  2363.     crtframe (5,5,15,10,0x1a,0); //draws the frame
  2364.     getch (); //pause
  2365.  
  2366.   //Draws a text frame with double outline
  2367.     prints ("Type = 1",26,3,0x1f);
  2368.     crtframe (25,5,35,10,0x1b,1);
  2369.     getch();
  2370.  
  2371.   //The outline now is in bold
  2372.     prints ("Type = 2",46,3,0x1f);
  2373.     crtframe (45,5,55,10,0x1c,2);
  2374.     getch ();
  2375.  
  2376.   //Draws a text frame with user defined outline (by default='█' (DBh))
  2377.     prints ("Type = 3",66,3,0x1f);
  2378.     crtframe (65,5,75,10,0x1d,3);
  2379.     getch ();
  2380.  
  2381.   //Outline now is character A. Changes user defined outline.
  2382.     prints ("Type = 256+'A'",3,13,0x1f);
  2383.     crtframe (5,15,15,20,0x1e,'A'+0x100);
  2384.     getch ();
  2385.  
  2386.   //Draws a text frame with user defined outline (now ='A' (41h))
  2387.     prints ("Type = 3 (again)",22,13,0x1f);
  2388.     crtframe (25,15,35,20,0x1f,3);
  2389.     getch ();
  2390.   }
  2391.  
  2392. :crtframew example:fillbarw example
  2393. %  crtframew and fillbarw example
  2394. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2395.  
  2396.  #include <CRT.H>
  2397.  #include <conio.h>
  2398.  
  2399.  void main ()
  2400.   {
  2401.     fillscr ('░',0x19);
  2402.     setcrtwin (10,5,30,15); //set crtwin_dta coordinates
  2403.     crtframew (0x1e,1); //draws the box frame
  2404.     getch ();
  2405.     fillbarw (' ',0x17); //fills the box internally
  2406.     getch ();
  2407.   }
  2408.  
  2409. :mkline_aux
  2410. % ▄▄▄▄▄▄▄▄▄▄▄▄
  2411. % ▌mkline_aux▐                         <~CRT.H~>
  2412. % ▀▀▀▀▀▀▀▀▀▀▀▀
  2413.     Performs frame characters auto replacement according to its arguments.
  2414.   It's ~mkline~'s replacement algorithm.
  2415.  
  2416. % Declaration:
  2417.     void  mkline_aux (int cnt, int var, unsigned int mode, int pos, int color);
  2418.  
  2419. % Remarks:
  2420.     The frame characters, as I will call are defined in mkline_mat buffer, and
  2421.   are these used to draw text box or text frames, as found in menus of programs
  2422.   like MS-DOS EDIT.
  2423.     mkline calls this function for any character to be analyzed and possibly
  2424.   replaced. mkline only manages the replacement.
  2425.  
  2426.     If the character found at position where the replacement will be done
  2427.   isn't in ~mkline_mat~ or if it is FFh, pos arguments is set internally to 3
  2428.   and it performs complete replacement (as drawing a line).
  2429.  
  2430.   arguments
  2431.  
  2432.     Arg.  │ What it is?, What it does?
  2433.   ════════╪═══════════════════════════════════════════════════════════════════
  2434.    cnt    │  It's the co-ordinate that remains constant in successive calls by
  2435.           │ mkline (may be either x or y)
  2436.    var    │  It's the co-ordinate that is incremented in each call by mkline.
  2437.           │ if (cnt==x var==y) if (cnt==y var==x)
  2438.    mode   │  Indicates the kind of line to be draw (outline and orientation)
  2439.    pos    │  Indicates in which position the replacement is going to be done
  2440.           │ (if it's going to be done at the beginning, at the middle, or at
  2441.           │ the end of line draw by mkline).
  2442.  
  2443.     The cnt and var arguments have the same meaning in mkline function, they
  2444.   define the position where the replacement occurs.
  2445.  
  2446.    mode value   │ use and operation. (by with mkline)
  2447.   ══════════════╪══════════════════════════════════════════
  2448.     0           │horizontal line drawing. Single outline
  2449.                 │y=cnt, x=var.
  2450.   ──────────────┼──────────────────────────────────────────
  2451.     1           │vertical line drawing. Single outline
  2452.                 │x=cnt, y=var.
  2453.   ──────────────┼──────────────────────────────────────────
  2454.     2           │horizontal line drawing. Double outline
  2455.                 │y=cnt, x=var.
  2456.   ──────────────┼──────────────────────────────────────────
  2457.     3           │vertical line drawing. Double outline.
  2458.                 │x=cnt, y=var.
  2459.  
  2460.    pos value    │ use and operation*
  2461.   ══════════════╪══════════════════════════════════════════
  2462.     0           │no replacement is done.
  2463.   ──────────────┼──────────────────────────────────────────
  2464.     1           │replacement with end direction trace.
  2465.                 │(used at the beginning of line)
  2466.   ──────────────┼──────────────────────────────────────────
  2467.     2           │replacement with beginning direction trace.
  2468.                 │(used at the end of line)
  2469.   ──────────────┼──────────────────────────────────────────
  2470.     3           │replacement with both directions trace.
  2471.                 │(used at the middle of line)
  2472.  
  2473.     * If character read at position doesn't exist in mkline_mat
  2474.     buffer or if it is FFh, not depending of pos value, it is internally
  2475.     assumed to be 3.
  2476.  
  2477.     The identification and replacement algorithm used by mkline_aux is based
  2478.   in finding the character's index on mkline_mat buffer and Boolean ORing it
  2479.   with mode and pos arguments.
  2480.   Uses functions ~getcrtchar~, ~getcrtcolor~ and ~printc~.
  2481.  
  2482. % Return Value:
  2483.     None.
  2484.  
  2485. % Portability:
  2486.     See ~Appendix A~.
  2487.  
  2488. % Examples:
  2489.     ~mkline_aux example 1~        ~mkline_aux example 2~
  2490.  
  2491. :mkline_aux example 1
  2492. %   mkline_aux example 1
  2493. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2494.  
  2495.  #include <CRT.H>
  2496.  #include <conio.h>
  2497.  
  2498.  void main ()
  2499.   {
  2500.     int c0,c1;
  2501.     fillscr ('░',0x19);
  2502.     prints ("* * * mkline_aux Example and use of mkline_mat * * *",14,1,0x1e);
  2503.     fillbar (mkline_mat[0x18],10,6,25,6,0x1f); //try also with mkline_mat[0x38]
  2504.     prints ("pos = ",10,8,0x1f);
  2505.     for (c0=0;c0<4;c0++)
  2506.      {
  2507.        getch ();
  2508.        printc (c0+0x30,16,8,0x1e);
  2509.        for (c1=0;c1<4;c1++)
  2510.         {
  2511.           mkline_aux (6,4*c0+c1+10,0,c0,0x1e); //draws the line over frame
  2512.                                             //characters.
  2513.           mkline_aux (4,4*c0+c1+10,0,c0,0x1e); //draws the upper line.
  2514.              //notice that it is the same call, the only difference is y value,
  2515.              //drawing the line where there's no frame character.
  2516.           //try also with argument mode=2 in calls to mkline_aux
  2517.         }
  2518.      }
  2519.     getch ();
  2520.   }
  2521.  
  2522. :mkline_aux example 2
  2523. %   mkline_aux example 2
  2524. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2525.  
  2526.  #include <CRT.H>
  2527.  #include <conio.h>
  2528.  
  2529.  //This program displays the contents of mkline_mat buffer onscreen and
  2530.  //what happens to the copy of mkline_mat on screen (inside the blue boxes)
  2531.  //after a call to mkline_aux.
  2532.  //Inside the green box is the contents of mkline_mat unchanged
  2533.  
  2534.  void main ()
  2535.   {
  2536.     int c0,c1,c2,c3;
  2537.     int a0,a1;
  2538.     for (c0=0;c0<4;c0++)
  2539.      {
  2540.        fillscr ('░',0x19);
  2541.        prints("* * * mkline_aux example and use of mkline_mat * * *",14,1,0x1e);
  2542.        setcrtwin(10,15,19,24);
  2543.        molduradw(0x1a);
  2544.        printtext((char *)mkline_mat,0,0,0x1f);
  2545.        prints (" => Contents of mkline_mat, unchanged.",26,20,0x1e);
  2546.        moldurad(39,16,47,18,0x1e);
  2547.        printsf (40,17,0x1f," pos=%d ",c0);
  2548.        for (c1=0;c1<4;c1++)
  2549.         {
  2550.           printsf (6+c1*20,3,0x1f,"mode = %d",c1);
  2551.           setcrtwin (5+c1*20,4,14+c1*20,13);
  2552.           molduradw(0x1b);
  2553.           printtext((char *)mkline_mat,0,0,0x1f);
  2554.           for (c2=0;c2<8;c2++)
  2555.              for (c3=0;c3<8;c3++)
  2556.               {
  2557.                 if (!(c1%2))
  2558.                    mkline_aux(c2+5,c3+c1*20+6,c1,c0,0x1e);
  2559.                  else
  2560.                    mkline_aux(c2+c1*20+6,c3+5,c1,c0,0x1e);
  2561.               }
  2562.         }
  2563.        getch ();
  2564.     }
  2565.   }
  2566.  
  2567.  
  2568. :mkline
  2569. % ▄▄▄▄▄▄▄▄
  2570. % ▌mkline▐                             <~CRT.H~>
  2571. % ▀▀▀▀▀▀▀▀
  2572.     Draws a menu frame line, performing automatic character replacement
  2573.   when it founds a menu frame character on its path.
  2574.  
  2575. % Declaration:
  2576.     void  mkline (int cnt, int bgn, int end, int color, unsigned int mode);
  2577.  
  2578.   Purpose:
  2579.  
  2580.     This function has been developed to make easy the programmer's work in
  2581.   drawing menu lines inside a box. For example, imagine that you have a menu
  2582.   box like the one draw below:
  2583.  
  2584.     ╔═══════╗
  2585.     ║       ║
  2586.     ║       ║
  2587.  A->║       ║<-B
  2588.     ║       ║
  2589.     ║       ║
  2590.     ╚═══════╝
  2591.  
  2592.     If you desired to divide it in two parts by drawing a line from A to
  2593.    B, you would have print a string from A to B with character '─'. The
  2594.    frame would appear in the best like this:
  2595.  
  2596.     ╔═══════╗
  2597.     ║       ║
  2598.     ║       ║
  2599.  A->║───────║<-B
  2600.     ║       ║
  2601.     ║       ║
  2602.     ╚═══════╝
  2603.  
  2604.     Note that the corners A and B aren't OK. The best would be the following:
  2605.  
  2606.     ╔═══════╗
  2607.     ║       ║
  2608.     ║       ║
  2609.  A->╟───────╢<-B
  2610.     ║       ║
  2611.     ║       ║
  2612.     ╚═══════╝
  2613.  
  2614.      One solution would be to print the characters ('╟' and '╢') at positions
  2615.   A and B, but that is too hard, because you need to know the ASCII codes of
  2616.   these characters, make one call to ~prints~ and two calls to ~printc~. With
  2617.   mkline, all you have to do is to supply it with the coordinates of A and
  2618.   one coordinate of B (only one is needed, because the other is supplied by A),
  2619.   the outline and the orientation of the line to be draw. Which becomes easier
  2620.   if you use ~linha...~ macros defined in CRT.H
  2621.  
  2622. % Remarks:
  2623.     The replacement is done from A thru B.
  2624.  
  2625.     Arguments:
  2626.     Arg.  │ What it is? What it does?
  2627.   ════════╪═══════════════════════════════════════════════════════════════════
  2628.    cnt    │ is the common coordinate of A and B
  2629.    bgn    │ is the other A coordinate
  2630.    end    │ is the other B coordinate
  2631.    mode   │ defines the orientation and outline of the line to be draw.
  2632.     If (cnt==column) bgn,end==row. If (cnt==row) bgn,end==column.
  2633.  
  2634.    mode value   │ use and operation.
  2635.   ══════════════╪══════════════════════════════════════════
  2636.     0           │horizontal line drawing. Single outline
  2637.                 │y=cnt, x=var.
  2638.   ──────────────┼──────────────────────────────────────────
  2639.     1           │vertical line drawing. Single outline
  2640.                 │x=cnt, y=var.
  2641.   ──────────────┼──────────────────────────────────────────
  2642.     2           │horizontal line drawing. Double outline
  2643.                 │y=cnt, x=var.
  2644.   ──────────────┼──────────────────────────────────────────
  2645.     3           │vertical line drawing. Double outline.
  2646.                 │x=cnt, y=var.
  2647.  
  2648.  
  2649.   mkline uses function ~mkline_aux~ as replacement algorithm.
  2650.  
  2651. % Return Value:
  2652.     None
  2653.  
  2654. % Portability:
  2655.     See ~Appendix A~.
  2656.  
  2657. % See Also:
  2658.     ~crtframe~    ~mkline_aux~    ~mkline_mat~
  2659.  
  2660. % Examples:
  2661.     ~Example 2~
  2662.  
  2663. %   crtwin example:
  2664.  
  2665.  #include <CRT.H>
  2666.  #include <conio.h>
  2667.  
  2668.  void main ()
  2669.   {
  2670.     fillscr ('░',0x19);
  2671.     printsj ("* * * Simple examples of mkline function * * *",1,0x1e);
  2672.     printsj ("- - - Hit any key to continue - - -",24,0x9e);
  2673.  
  2674.   //The example above (the one you had to imagine):
  2675.     moldurad (20,6,30,10,0x1f);
  2676.     getch ();
  2677.     mkline (8,20,30,0x1e,0);
  2678.     getch ();
  2679.  
  2680.   //another example
  2681.     moldura (50,6,60,10,0x1f);
  2682.     getch ();
  2683.     mkline (55,6,10,0x1e,3);
  2684.     getch ();
  2685.   }
  2686.  
  2687. :crtwindow
  2688. % ▄▄▄▄▄▄▄▄▄▄▄▄
  2689. % ▌crtwindow ▐                         <~CRT.H~>
  2690. % ▀▀▀▀▀▀▀▀▀▀▀▀
  2691.     Draws a text box with border and title.
  2692.  
  2693. % Declaration:
  2694.     void crtwindow    (struct ~crtwin_inp~ p0);
  2695.  
  2696. % Remarks:
  2697.     p0 is the input struct filled with input arguments for crtwindow.
  2698.     If p0.title==NULL it doesn't print any title nor lefts any space for the
  2699.   title.
  2700.     The box coordinates are given by ~crtwin_dta~ global variable.
  2701.     Before calling crtwindow crtwin_dta values must be set to values inside
  2702.   the screen, otherwise the box will not appear completely.
  2703.     crtwindow doesn't truncate the title to fit in the box upper border. So
  2704.   if the title is very big or the box is narrow, the title will exceed the
  2705.   box width.
  2706.  
  2707. % Return Value:
  2708.     None.
  2709.  
  2710. % Portability:
  2711.     See ~Appendix A~.
  2712.  
  2713. % See Also:
  2714.     ~crtframe~    ~mkline~     ~setcrtwin~
  2715.  
  2716. % Examples:
  2717.     ~Example 3~
  2718.  
  2719. %   crtwindow example:
  2720.  
  2721.  #include <CRT.H>
  2722.  #include <conio.h>
  2723.  
  2724.  void main ()
  2725.   {
  2726.     struct crtwin_inp licos;
  2727.     licos.title="CRTWINDOW EXAMPLE"; //title
  2728.     licos.tcolor=0x1b; //title color
  2729.     licos.fchr='▒'; //fill character
  2730.     licos.fcolor=0x2a; //fill color
  2731.     licos.bcolor=0x1f; //border color
  2732.     licos.btype=1; //border type, same of crtframe
  2733.  
  2734.     fillscr ('░',0x19);
  2735.     setcrtwin (10,5,30,15); //the coordinates for crtwindow
  2736.     crtwindow (licos);
  2737.  
  2738.     licos.title=NULL;
  2739.     licos.fcolor=0x19;
  2740.     licos.bcolor=0x1e;
  2741.     setcrtwin (52,5,68,14);
  2742.     crtwindow (licos);
  2743.     getch ();
  2744.   }
  2745.  
  2746. :savevideo:restorevideo:savevideowin:restorevideowin:savevideow:restorevideow:savevideo...:restorevideo...
  2747. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2748. % ▌savevideo,     restorevideo,    ▐   <~CRT.H~>
  2749. % ▌savevideowin,  restorevideowin, ▐
  2750. % ▌savevideow and restorevideow    ▐
  2751. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2752.    ■ savevideo saves the contents of screen into a far buffer.
  2753.    ■ restorevideo restores the contents of screen previously saved into a far
  2754.      buffer.
  2755.    ■ savevideowin saves the contents of a text window into a far buffer.
  2756.    ■ restorevideowin restores the contents of a text window previously saved
  2757.      into a far buffer.
  2758.    ■ savevideow is similar to savevideowin, but the window coordinates are
  2759.      given by ~crtwin_dta~.
  2760.    ■ restorevideow is similar to savevideowin, but the window coordinates are
  2761.      given by crtwin_dta.
  2762.  
  2763.  
  2764. % Declaration:
  2765.    ■ char far *savevideo       (char far *s);
  2766.    ■ char far *restorevideo    (char far *s);
  2767.    ■ char far *savevideowin    (char far *s, int xi, int yi, int xf, int yf);
  2768.    ■ char far *restorevideowin (char far *s, int xi, int yi, int xf, int yf);
  2769.    ■ char far *savevideow      (char far *s);
  2770.    ■ char far *restorevideow   (char far *s);
  2771.  
  2772.  
  2773. % Remarks:
  2774.     If ~vmode_x~ and ~vmode_y~ corresponds to the actual number of rows and
  2775.   columns in current text mode, savevideo and restorevideo use the hole screen.
  2776.     savevideowin and restorevideowin use only a rectangle (text window)
  2777.   which upper left corner is (xi,yi), and lower right corner is (xf,yf).
  2778.     (xi,yi) and (xf,yf) doesn't need to be inside the range given by vmode_x
  2779.   and vmode_y for these functions work. For example:
  2780.     savevideowin(buffer,-2,-2,100,60);
  2781.   is a valid call.
  2782.     savevideow/restorevideow calls savevideowin/restorevideowin with:
  2783.        xi=crtwin_dta.left;     yi=crtwin_dta.top;
  2784.        xf=crtwin_dta.right;    yf=crtwin_dta.bottom;
  2785.  
  2786.     In savevideo, the buffer size must be at least 2*(vmode_x * vmode_y) to
  2787.   avoid possible data loss, which normally causes unpredictable and
  2788.   likely disastrous results, and can lead to serious problems.
  2789.     In savevideowin, the buffer size must be at least 2*(yf-yi+1)(xf-xi+1), by
  2790.   the same reason as above. (even when xi, xf ,yi ,yf are out of range given
  2791.   by vmode_x and vmode_y)
  2792.     If you save many screens or windows in the same buffer, remember that
  2793.   the buffer size must be at least the sum of required size for each screen or
  2794.   window. The formulas above determines the required size for each screen or
  2795.   window data storage.
  2796.     savevideo and restorevideo use only the memory area that goes from
  2797.   ~video_addr~ thru video_addr + 2*vmode_x*vmode_y - 1 (when ~crt_direct~==0),
  2798.   and/or the window (0,0) thru (vmode_x-1,vmode_y-1) (always).
  2799.  
  2800.     When is defined ~CRT_FULL~ before including CRT.H these functions are
  2801.   replaced by macros that have equivalent functionality, but use ~savecrt...~
  2802.   and ~restorecrt...~ functions.
  2803.    (for further information see these macros or CRT.H file)
  2804.  
  2805. % Return Value:
  2806.     All these functions return a pointer that points to buffer's next free
  2807.   position, that is, the position where the next screen or window can be saved
  2808.   or retrieved.
  2809.  
  2810. % Portability:
  2811.     See ~Appendix A~.
  2812.  
  2813. % Hardware Compatibility:
  2814.     Depends on ~printc~, ~getcrtchar~ and ~getcrtcolor~ compatibility.
  2815.  
  2816. % See Also:
  2817.     ~CRT_FULL~ #defines     ~savecrt...~     ~restorecrt...~
  2818.     ~crtwin_dta~            ~gettext~        ~puttext~
  2819.  
  2820. % Examples:
  2821.     ~savevideo example~                ~restorevideo example~
  2822.     ~savevideowin example~             ~restorevideowin example~
  2823.     ~savevideow example~               ~restorevideow example~
  2824.  
  2825. :savevideo example:restorevideo example
  2826. %   savevideo and restorevideo example
  2827. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2828.  
  2829.  #include <CRT.H>
  2830.  #include <conio.h>
  2831.  
  2832.  void main ()
  2833.   {
  2834.     char buffer[4096]; //buffer>=4000= 2*(25 * 80) Be sure that vmode_x<=80
  2835.                        //and vmode_y<=25
  2836.     fillscr ('░',0x19);
  2837.     prints ("* * * SAVEVIDEO AND RESTOREVIDEO EXAMPLE * * *",17,1,0x1e);
  2838.     prints ("- - - Hit any key to continue - - -",23,24,0x9e);
  2839.     getch ();
  2840.     savevideo (buffer); //saves in buffer "buffer" the screen contents
  2841.     fillscr (' ',7); //clears the screen
  2842.     prints ("- - - Hit any key to see previous screen - - -",16,24,7);
  2843.     getch ();
  2844.     restorevideo (buffer); //restore the screen contents saved in "buffer"
  2845.     getch ();
  2846.   }
  2847.  
  2848. :savevideowin example:restorevideowin example
  2849. %   savevideowin and restorevideowin example
  2850. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2851.  
  2852.  #include <CRT.H>
  2853.  #include <conio.h>
  2854.  
  2855.  void main ()
  2856.   {
  2857.     char buffer[420]; // buffer>= 420 = 2*(74-5+1) * (24-22+1)
  2858.     fillscr ('░',0x19);
  2859.     prints ("* * * SAVEVIDEOWIN AND RESTOREVIDEOWIN EXAMPLE * * *",13,1,0x1e);
  2860.     prints ("- - - Hit any key to continue - - -",20,24,0x9e);
  2861.     getch ();
  2862.     savevideowin (buffer,5,22,74,24); //saves in "buffer" a text window
  2863.     fillscr (' ',0x07); //clears the screen
  2864.     prints ("- - - Hit any key to see a part of previous screen - - -",11,23,7);
  2865.     getch ();
  2866.     restorevideowin(buffer,5,11,74,13);//restores saved window at a new position
  2867.     getch ();
  2868.   }
  2869.  
  2870. :savevideow example:restorevideow example
  2871. %   savevideow and restorevideow example
  2872. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2873.  
  2874.  #include <CRT.H>
  2875.  #include <conio.h>
  2876.  
  2877.  void main ()
  2878.   {
  2879.     char buffer[462]; // buffer>= 462 = 2*(50-30+1) * (15-5+1)
  2880.     fillscr ('░',0x19);
  2881.     printsj ("* * * SAVEVIDEOW AND RESTOREVIDEOW EXAMPLE * * *",1,0x1e);
  2882.     printsj ("- - - Hit any key to continue - - -",24,0x9e);
  2883.     setcrtwin(30,5,50,15);
  2884.     molduradw (0x1e);
  2885.     fillbarw ('■',0x18);
  2886.     printsj("This box is stored",1,0x1f);
  2887.     printsj("in a buffer",2,0x1f);
  2888.     getch ();
  2889.     savevideow (buffer);
  2890.        //saves in "buffer" the text window defined by crtwin_dta
  2891.     fillscr (' ',0x07); //clears the screen
  2892.     prints ("- - - Hit any key to see the text box again - - -",16,23,7);
  2893.     getch ();
  2894.     restorevideow (buffer);
  2895.        //restores saved window at position given by crtwin_dta
  2896.     getch ();
  2897.   }
  2898.  
  2899. :CRT_FULL:SAVECRT·:RESTORECRT·:SAVECRTWIN·:RESTORECRTWIN·
  2900. %  CRT_FULL #defines                   <~CRT.H~>
  2901. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2902.  
  2903.   SAVECRT, RESTORECRT, SAVECRTWIN, RESTORECRTWIN, OR CRT_FULL are #defines
  2904.   needed to be defined before including CRT.H to include ~savecrt...~ and
  2905.   ~restorecrt...~ functions. They have been created to allow optimization
  2906.   (about 600 bytes all them together).
  2907.  
  2908.   For example:
  2909.     savecrt has the same functionality of savevideo, the difference is that
  2910.   savecrt has more options than savevideo, being larger. So if the program
  2911.   requires only savevideo, it would be a waste of memory and code to use
  2912.   savecrt working as savevideo. But if a program requires both savevideo
  2913.   and savecrt, it would be a waste to include savevideo, because savecrt can
  2914.   do everything as well as savevideo does and there's almost no difference in
  2915.   execution time between both functions, so including savevideo code's would
  2916.   be useless. It would pay off including both functions only if both appears
  2917.   hundreds time in source code, in a way that the extra argument that savecrt
  2918.   has would make difference in size.
  2919.     So what has been done is a mechanism that allows only one of both
  2920.   functions to be used. For example, a program A uses only savevideo (see
  2921.   example below), but then the programmer decides to include in this program
  2922.   savecrt function (program B).
  2923.  
  2924.      Program A:                            Program B:
  2925.  
  2926.                                         #define SAVECRT
  2927.  #include <CRT.H>                       #include <CRT.H>
  2928.  void main ()                           void main ()
  2929.   {                                      {
  2930.     char s[4000];                          char s1[4000];
  2931.     savevideo(s);  //savevideo(s);         char s2[2000];
  2932.     .                                      savevideo (s); //savecrt(s,0)
  2933.     .                                      savecrt (s2,2);
  2934.     .                                      .
  2935.     .                                      .
  2936.                                            .
  2937.  
  2938.     To compile program B, the programmer will be forced to define SAVECRT
  2939.   before including CRT.H. By defining SAVECRT, savevideo is replaced by a
  2940.   macro with the same name that calls savecrt. So, even if the source code
  2941.   appears to use both functions, in fact it uses only savecrt.
  2942.     However if the programmer wishes to include both functions in the
  2943.   compiled code, he/she has to undefine the macro that replaces savevideo
  2944.   before the call to savevideo, as follows:
  2945.     #undef savevideo
  2946.  
  2947.     The same idea is valid for other functions listed in the table below
  2948.   with their respectively macros and equivalent functions:
  2949.  
  2950.   ~savevideo~        ~savecrt~        SAVECRT
  2951.   ~restorevideo~     ~restorecrt~     RESTORECRT
  2952.   ~savevideowin~     ~savecrtwin~     SAVECRTWIN
  2953.   ~restorevideowin~  ~restorecrtwin~  RESTORECRTWIN
  2954.   ~savevideow~       ~savecrtw~       SAVECRTWIN
  2955.   ~restorevideow~    ~restorecrtw~    RESTORECRTWIN
  2956.  
  2957.  
  2958.     If you use all these functions, instead of defining these four macros
  2959.   in the table above, you may define CRT_FULL. By doing so, CRT.H
  2960.   automatically defines these four macros.
  2961.  
  2962.  #define CRT_FULL
  2963.     is the same as (internally defines)
  2964.  #define SAVECRT
  2965.  #define RESTORECRT
  2966.  #define SAVECRTWIN
  2967.  #define RESTORECRTWIN
  2968.  
  2969.     For further information see CRT.H file.
  2970.     If you think that this macro structure is too complicated, you may remove
  2971.   it editing CRT.H file.
  2972.  
  2973. :savecrt:restorecrt:savecrtwin:restorecrtwin:savecrtw:restorecrtw:savecrt...:restorecrt...
  2974. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2975. % ▌savecrt,      restorecrt,   ▐       <~CRT.H~>
  2976. % ▌savecrtwin,   restorecrtwin,▐
  2977. % ▌savecrtw  and restorecrtw   ▐
  2978. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  2979.   These functions do the following:
  2980.    ■ savecrt saves the contents of screen into a far buffer;
  2981.    ■ restorecrt restores the contents of screen previously saved into a far
  2982.      buffer;
  2983.    ■ savecrtwin saves the contents of a text window into a far buffer;
  2984.    ■ restorecrtwin restores the contents of a text window previously saved
  2985.      into a far buffer;
  2986.    ■ savevideow is similar to savevideowin, but the window coordinates are
  2987.      given by crtwin_dta.
  2988.    ■ restorevideow is similar to savevideowin, but the window coordinates are
  2989.      given by crtwin_dta.
  2990.  
  2991.   all them with options (mode).
  2992.  
  2993. % Declaration:
  2994.    ■ char far *savecrt      (char far *s, int mode);
  2995.    ■ char far *restorecrt   (char far *s, int mode);
  2996.    ■ char far *savecrtwin   (char far *s, int xi, int yi, int xf, int yf,
  2997.                              int mode);
  2998.    ■ char far *restorecrtwin(char far *s, int xi, int yi, int xf, int yf,
  2999.                              int mode);
  3000.    ■ char far *savecrtw     (char far *s, int mode);
  3001.    ■ char far *restorecrtw  (char far *s, int mode);
  3002.  
  3003.  
  3004. % Remarks:
  3005.     savecrt, restorecrt, savecrtwin, restorecrtwin, savecrtw and restorecrtw
  3006.   are similar to their ~savevideo...~ and ~restorevideo...~ counterparts,
  3007.   except that they have one more input parameter, which defines the mode that
  3008.   data must be saved or retrieved from buffer, the mode argument.
  3009.     (xi,yi) is the upper left corner.
  3010.     (xf,yf) is the lower right corner.
  3011.     (xi,yi) and (xf,yf) doesn't need to be inside the range given by vmode_x
  3012.   and vmode_y for these functions work. For example:
  3013.     savecrtwin(buffer,-2,-2,100,60);
  3014.   is a valid call.
  3015.  
  3016.     savecrtw/restorecrtw calls savecrtwin/restorecrtwin with:
  3017.        xi=crtwin_dta.left;     yi=crtwin_dta.top;
  3018.        xf=crtwin_dta.right;    yf=crtwin_dta.bottom;
  3019.  
  3020.     If mode==0, these functions work exactly as the same as their ...video...
  3021.   counterparts, except that they are a bit larger.
  3022.  
  3023.     mode values:
  3024.  
  3025.   mode│ Function
  3026.  ═════╪══════════════════════════════════════════════════════════════════
  3027.    0  │ Writes or reads characters and attributes (colors) sequentially
  3028.    1  │ Writes or reads attributes and characters sequentially
  3029.    2  │ Writes or reads only characters
  3030.    3  │ Writes or reads only attributes
  3031.    >3 │ Reserved for future versions
  3032.  
  3033.     If mode is greater than 3 the call these functions is ignored and
  3034.   they return NULL.
  3035.  
  3036.     Hint: You can exchange characters by colors on screen using a call to
  3037.  savecrt... with mode==0 and restoring the saved screen (or window) at
  3038.  the same position with mode==1.
  3039.  
  3040.      To use them is needed to define the matching #define or define CRT_FULL
  3041.   before including CRT.H (See table below)
  3042.  
  3043.   Function      │ Lines before #include <CRT.H> (in source code)
  3044.  ═══════════════╪═════════════════════════════════════════════════════════
  3045.  savecrt        │#define SAVECRT        or    #define CRT_FULL
  3046.  restorecrt     │#define RESTORECRT     or    #define CRT_FULL
  3047.  savecrtwin     │#define SAVECRTWIN     or    #define CRT_FULL
  3048.  restorecrtwin  │#define RESTORECRTWIN  or    #define CRT_FULL
  3049.  savecrtw       │#define SAVECRTWIN     or    #define CRT_FULL
  3050.  restorecrtw    │#define RESTORECRTWIN  or    #define CRT_FULL
  3051.  
  3052.  
  3053.     For further information, see CRT_FULL #defines.
  3054.  
  3055.     The buffer "s" size must be at least: *
  3056.   - for mode==0 or mode==1:
  3057.        s>=(2 * vmode_x * vmode_y) => for savecrt and restorecrt
  3058.        s>=(2 * (xf-xi+1) * (yf-yi+1)  => for savecrtwin and restorecrtwin
  3059.   - for mode==2 or mode==3:
  3060.        s>=vmode_x * vmode_y => for savecrt and restorecrt
  3061.        s>=(xf-xi+1) * (yf-yi+1)  => for savecrtwin and restorecrtwin
  3062.  
  3063.    * Even when xi, xf ,yi ,yf are out of range given by vmode_x and vmode_y
  3064.  
  3065.     If you save many screens or windows in the same buffer, remember that
  3066.   the buffer size must be at least the sum of required size for each screen
  3067.   or window. The formulas above determines the required size for each
  3068.   screen or window data storage.
  3069.  
  3070. % Return Value:
  3071.     On success: These functions return a pointer that points to buffer's
  3072.   next free position, that is, the position where can be saved or retrieved
  3073.   the next screen or window. (see examples)
  3074.     On error: these functions return NULL. (only happens if mode is invalid)
  3075.  
  3076. % Portability:
  3077.     See ~Appendix A~.
  3078.  
  3079. % Hardware Compatibility:
  3080.     Depends on ~printc~, ~getcrtchar~ and ~getcrtcolor~ compatibility.
  3081.  
  3082. % See Also:
  3083.     ~CRT_FULL~ #defines     ~savevideo...~   ~restorevideo...~
  3084.     ~crtwin_dta~            ~gettext~        ~puttext~
  3085.  
  3086. % Examples:
  3087.     ~savecrt example~                  ~restorecrt example~
  3088.     ~savecrtwin example~               ~restorecrtwin example~
  3089.     ~savecrtw example~                 ~restorecrtw example~
  3090.  
  3091. :savecrt example:restorecrt example
  3092. %   savecrt and restorecrt example
  3093. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3094.  
  3095.  /* In this example is used a 4000 bytes buffer. The first 2000 bytes are used
  3096.  by the first savecrt call to save the characters from screen, returning
  3097.  a pointer that points to the rest of the buffer. This pointer is used by a
  3098.  second savecrt call to save the attributes from screen in the remaining 2000
  3099.  bytes*/
  3100.  
  3101.  #define SAVECRT      //or
  3102.  #define RESTORECRT   //#define CRT_FULL
  3103.  
  3104.  #include <CRT.H>
  3105.  #include <conio.h>
  3106.  
  3107.  void main ()
  3108.   {
  3109.     char savebuf[4000]; //savebuf>=(25 * 80) + (25 * 80)
  3110.     char *savebuf2;
  3111.     fillscr ('░',0x19);
  3112.     prints ("* * * SAVECRT AND RESTORECRT EXAMPLE * * *",18,1,0x1e);
  3113.     prints ("- - - Hit any key to continue - - -",22,24,0x9e);
  3114.     getch ();
  3115.     savebuf2=(char *)savecrt(savebuf,2);//saves first the characters(2000 bytes)
  3116.     savecrt(savebuf2,3); //saves the attributes (remaining 2000 bytes)
  3117.     fillscr (' ',0x07);
  3118.     printsn ("- - - Hit any key to see previous screen - - -",16,23);
  3119.     printsn ("- - - first characters, then colors - - -",18,24);
  3120.     getch ();
  3121.     savebuf2=savebuf;
  3122.     savebuf2=(char *)restorecrt (savebuf2,2);
  3123.     getch ();
  3124.     restorecrt (savebuf2,3);
  3125.     getch ();
  3126.   }
  3127.  
  3128. :savecrtwin example:restorecrtwin example
  3129. %   savecrtwin and restorecrtwin example
  3130. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3131.  
  3132.  /* In this example is used a 272 bytes buffer. The first 136 bytes are used
  3133.  by the first savecrtwin call to save the characters from screen, returning
  3134.  a pointer that points to the rest of the buffer. This pointer is used by a
  3135.  second savecrtwin call to save the attributes from screen in the remaining
  3136.  136 bytes*/
  3137.  
  3138.  #define SAVECRTWIN      //or
  3139.  #define RESTORECRTWIN   //#define CRT_FULL
  3140.  
  3141.  #include <CRT.H>
  3142.  #include <conio.h>
  3143.  
  3144.  void main ()
  3145.   {
  3146.     char savebuf[272]; //savebuf>=272=((72-5+1)*(24-23+1)) +((72-5+1)*(24-23+1))
  3147.     char *savebuf2;
  3148.     fillscr ('░',0x19);
  3149.     prints ("* * * SAVECRTWIN AND RESTORECRTWIN EXAMPLE * * *",18,1,0x1e);
  3150.     prints ("- - - Hit any key to continue - - -",22,24,0x9e);
  3151.     getch ();
  3152.     savebuf2=(char *)savecrtwin(savebuf,5,23,72,24,3); //saves first attributes
  3153.     savecrtwin(savebuf2,5,23,72,24,2); //then saves characters
  3154.     fillscr (' ',0x07);
  3155.     printsj("- - - Hit any key to see a part of previous screen - - -",23,0x07);
  3156.     printsj ("- - - first attributes (colors), then characters - - -",24,0x07);
  3157.     getch ();
  3158.     savebuf2=savebuf;
  3159.     savebuf2=(char *)restorecrtwin(savebuf2,5,20,72,21,3);
  3160.     getch ();
  3161.     restorecrtwin (savebuf2,5,20,72,21,2);
  3162.     getch ();
  3163.   }
  3164.  
  3165. :savecrtw example:restorecrtw example
  3166. %   savecrtw and restorecrtw example
  3167. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3168.  
  3169.  /* In this example is used a 272 bytes buffer. The first 136 bytes are used
  3170.  by the first savecrtw call to save the characters from screen, returning
  3171.  a pointer that points to the rest of the buffer. This pointer is used by a
  3172.  second savecrtw call to save the attributes from screen in the remaining
  3173.  136 bytes*/
  3174.  
  3175.  #define SAVECRTWIN      //or
  3176.  #define RESTORECRTWIN   //#define CRT_FULL
  3177.  
  3178.  #include <CRT.H>
  3179.  #include <conio.h>
  3180.  
  3181.  void main ()
  3182.   {
  3183.     char savebuf[272]; //savebuf>=272=((72-5+1)*(24-23+1)) +((72-5+1)*(24-23+1))
  3184.     char *savebuf2;
  3185.     fillscr ('░',0x19);
  3186.     prints ("* * * SAVECRTW AND RESTORECRTW EXAMPLE * * *",18,1,0x1e);
  3187.     prints ("- - - Hit any key to continue - - -",22,24,0x9e);
  3188.     getch ();
  3189.     setcrtwin (5,23,72,24);
  3190.     savebuf2=(char *)savecrtw(savebuf,3); //saves first attributes
  3191.     savecrtw(savebuf2,2); //then saves characters
  3192.     fillscr (' ',0x07);
  3193.     prints ("- - - Hit any key to see a part of previous screen - - -",
  3194.       12,23,0x07);
  3195.     prints ("- - - first attributes (colors), then characters - - -",
  3196.       13,24,0x07);
  3197.     getch ();
  3198.     setcrtwin (5,20,72,21);
  3199.     savebuf2=(char *)restorecrtw(savebuf,3);
  3200.     getch ();
  3201.     restorecrtw (savebuf2,2);
  3202.     getch ();
  3203.   }
  3204.  
  3205. :setcursorsh:getcursorsh
  3206. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3207. % ▌setcursorsh and getcursorsh▐        <~CRT.H~>
  3208. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3209.     ■ setcursorsh changes cursor shape
  3210.     ■ getcursorsh gets cursor shape
  3211.  
  3212. % Declaration:
  3213.     ■ void setcursorsh (unsigned shape);
  3214.     ■ int getcursorsh (void);
  3215.  
  3216. % Remarks:
  3217.  
  3218.     ■ setcursorsh uses function INT 10h / AH = 01h
  3219.     ■ getcursorsh uses function INT 10h / AH = 03h
  3220.  
  3221.     shape argument bits.  (source: Ralf's Brown ~Interrupt List~ / some tests)
  3222.        15 must be 0.
  3223.        14,13 cursor blinking
  3224.           (00=normal, 01=invisible, 10=erratic, 11=slow)
  3225.           (00=normal, other=invisible on EGA/VGA)
  3226.        12-8 topmost scan line containing cursor
  3227.        7    When calling setcursorsh this bit should be set in some video
  3228.             adapters (or system configuration) for the cursor shape be
  3229.             correctly changed (undocumented). I've tested setcursorsh in
  3230.             my computer (The video adapter is SVGA and DISPLAY.SYS was
  3231.             installed) and it worked fine only when this bit was set.
  3232.             Do some tests with this bit set and clear.
  3233.        4-0  lowermost scan line containing cursor
  3234.  
  3235.     setcursorsh loads _AL with ~vmode_mode~, before calling INT 10, to avoid
  3236.   problem with some buggy BIOSes
  3237.     Important Notice: It has been reported in INT 10h/AH=01h documentation that
  3238.   AMI 386 BIOS and AST Premier 386 BIOS will lock up the system if AL is not
  3239.   equal to current video mode. So when calling setcursorsh in systems that
  3240.   use these BIOSes, be sure that vmode_mode corresponds to the actual selected
  3241.   mode.
  3242.  
  3243.   On VGA/SVGA systems:
  3244.     In 25 rows text modes, the cursor is draw with 16 horizontal lines. In 43
  3245.   or 50 rows text modes, the cursor is draw with 8 horizontal lines.
  3246.  
  3247.   On CGA systems the cursor is draw with 8 horizontal lines, in 25 rows
  3248.  text modes.
  3249.  
  3250.   shape example: shape = 0506h
  3251.  
  3252.        line 0// ░░░░░░░░
  3253.        line 1// ░░░░░░░░
  3254.        line 2// ░░░░░░░░
  3255.        line 3// ░░░░░░░░
  3256.        line 4// ░░░░░░░░
  3257.        line 5// ████████
  3258.        line 6// ████████
  3259.        line 7// ░░░░░░░░
  3260.  
  3261.   IMPORTANT: When calling getcursorsh (INT 10h/AH=03h) many ROM BIOSes
  3262.   incorrectly return the cursor default size for a color display (start 06h,
  3263.   end 07h) when a monochrome display is attached.
  3264.  
  3265. % Return Value:
  3266.     ■ setcursorsh returns nothing.
  3267.     ■ getcursorsh returns the current cursor shape in video page defined by
  3268.       crt_page.
  3269.  
  3270. % Portability:
  3271.     On DOS window mode (WINDOWS), it has same effect.
  3272.     See ~Appendix A~ for further information.
  3273.  
  3274. % Hardware Compatibility:
  3275.     Probably every PC compatible video adapter.
  3276.  
  3277. % Examples:
  3278.  
  3279.  #include <CRT.H>
  3280.  #include <conio.h>
  3281.  
  3282.  void main () //turns cursor invisible for a moment
  3283.   {
  3284.     int a0;
  3285.     a0=getcursorsh (); //a0=old cursor shape
  3286.     getch (); //pause
  3287.     setcursorsh (0x2000); //turns cursor invisible
  3288.     getch ();
  3289.     setcursorsh (a0); //restores cursor shape
  3290.     getch ();
  3291.   }
  3292.  
  3293.  #include <CRT.H>
  3294.  #include <conio.h>
  3295.  
  3296.  void showcursorsh (int y)
  3297.  //displays the current cursor shape
  3298.  //y == row where message will be displayed
  3299.   {
  3300.     printsf (20,y,0x1f,"%.4Xh :  █",
  3301.     getcursorsh());
  3302.     getch ();
  3303.   }
  3304.  
  3305.  void main ()
  3306.   {
  3307.     int shape;
  3308.     textmode (3);
  3309.     fillscr (' ',0x1e);
  3310.     printsj ("* * * 25 LINES TEXT MODE * * *",0,0x1e);
  3311.     printsj ("- - - Hit any key for the next example - - -",15,0x9e);
  3312.     shape=getcursorsh(); //saves initial cursor shape
  3313.     printsf (4,12,0x1f,"initial shape = %.4Xh :  █",shape);
  3314.     //outputs the initial cursor shape
  3315.     gotoxy (28,13);
  3316.     getch ();
  3317.  
  3318.     prints ("selected",3 ,12,0x1f);
  3319.     setcursorsh (0x0203);   showcursorsh (12);
  3320.     setcursorsh (0x0f0f);   showcursorsh (12);
  3321.     setcursorsh (0x000f);   showcursorsh (12);
  3322.     setcursorsh (0x0605);   showcursorsh (12);
  3323.  
  3324.     textmode (64);
  3325.     videomode (64);
  3326.     crtwin_dta.bottom=50;
  3327.     fillscr (' ',0x1e);
  3328.     printsj ("* * * 50 OR 43 LINES TEXT MODE * * *",0,0x1e);
  3329.     printsj ("- - - Hit any key for the next example - - -",30,0x9e);
  3330.     prints ("selected shape =",3,22,0x1f);
  3331.     gotoxy (28,23);
  3332.  
  3333.     setcursorsh (0x0001);   showcursorsh (22);
  3334.     setcursorsh (0x0102);   showcursorsh (22);
  3335.     setcursorsh (0x0203);   showcursorsh (22);
  3336.     setcursorsh (0x0304);   showcursorsh (22);
  3337.     setcursorsh (0x0607);   showcursorsh (22);
  3338.     setcursorsh (0x080C);   showcursorsh (22);
  3339.  
  3340.     barcolor (0,30,79,30,0x11);
  3341.     printsj ("- - - HIT ANY KEY TO EXIT - - -",30,0x9c);
  3342.     getch ();
  3343.     textmode (3); //set default text mode
  3344.     setcursorsh (shape);//restores initial cursor shape.
  3345.    }
  3346.  
  3347. :setpalreg:getpalreg
  3348. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3349. % ▌setpalreg and getpalreg▐            <~CRT.H~>
  3350. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3351.     ■ setpalreg sets a single palette register value, enabling to change usual
  3352.        text colors by others.
  3353.     ■ getpalreg gets individual palette register value.
  3354.  
  3355. % Declaration:
  3356.     ■ void setpalreg (int regpal, int val);
  3357.     ■ int getpalreg (int regpal);
  3358.  
  3359. % Remarks:
  3360.     ■ setpalreg uses function INT 10h / AX = 1000h
  3361.     ■ getpalreg uses function INT 10h / AX = 1007h
  3362.  
  3363.     setpalreg loads the register given by (regpal) with value given by (val).
  3364.     For (regpal == 00h through 0Fh) regpal is a palette register and val is a
  3365.   DAC register.
  3366.     For (regpal == 11h) regpal is overscan color register and val is a DAC
  3367.   register.
  3368.     For (regpal == 10h,12h,13h,14h) regpal is a specific CRT register and
  3369.   val is it's value. You should beware that misprogramming of these register
  3370.   may cause undesired results or disastrous results, specially register 10h,
  3371.   which you should let BIOS control.
  3372.      regpal values greater than 0Fh are undocumented, so not necessarily
  3373.   this information above and the table below will be correct for regpal values
  3374.   greater or equal to 10h.
  3375.     The table below summarizes regpal values and the register accessed
  3376.  
  3377.     regpal   Register Accessed
  3378.  
  3379.    00-0Fh    palette register
  3380.     10h      attribute mode control register (should let BIOS control this)
  3381.     11h      overscan color register (see also AX=1001h)
  3382.     12h      color plane enable register (bits 3-0 enable corresponding
  3383.              text attribute bit)
  3384.     13h      horizontal PEL panning register
  3385.     14h      color select register
  3386.  
  3387.     The DAC register is the register that holds the color that's is being
  3388.   used as overscan color and/or by a (or many) palette register.
  3389.     In most CRT.H functions and ~CONIO.H~ functions the color/attribute
  3390.   is a combination where bits 6-4 selects the palette register for background
  3391.   color and bits 3-0 selects the foreground color. Bit 7 is usually text
  3392.   blinking enable bit, but it may be reprogrammed to be background color
  3393.   bit. (see ~settextblink~ and ~Appendix B~)
  3394.     In VGA/SVGA or better adapters, the DAC register for a palette register
  3395.   or is selected by the (6 or 4) least significant bits of palette register
  3396.   value plus current video DAC color page times the size (in DAC registers)
  3397.   of a page. (see also setdacpage).
  3398.     In other adapters the DAC register for a palette register is given by
  3399.   it's value (not tested).
  3400.  
  3401.     The overscan register is not affected by DAC registers paging.
  3402.  
  3403.      For further details see the source code and INT 10h / AX=(1000h/1007h) in
  3404.   Ralf's Brown ~Interrupt List~.
  3405.  
  3406.   Standard values for palette registers:
  3407.  
  3408.      regpal* │     Color    │ val**
  3409.    ══════════╪══════════════╪═══════
  3410.        0     │ BLACK        │  0
  3411.        1     │ BLUE         │  1
  3412.        2     │ GREEN        │  2
  3413.        3     │ CYAN         │  3
  3414.        4     │ RED          │  4
  3415.        5     │ MAGENTA      │  5
  3416.        6     │ BROWN        │ 20
  3417.        7     │ LIGHTGRAY    │  7
  3418.        8     │ DARKGRAY     │ 56
  3419.        9     │ LIGHTBLUE    │ 57
  3420.       10     │ LIGHTGREEN   │ 58
  3421.       11     │ LIGHTCYAN    │ 59
  3422.       12     │ LIGHTRED     │ 60
  3423.       13     │ LIGHTMAGENTA │ 61
  3424.       14     │ YELLOW       │ 62
  3425.       15     │ WHITE        │ 63
  3426.    ──────────┼──────────────┼───────
  3427.       17***  │ OVERSCAN     │  0
  3428.  
  3429.    * palette register number (onscreen text color (see ~Appendix B~))
  3430.   ** palette register value (range: 0-63) (same of EGA_COLORS)
  3431.  *** overscan register (undocumented) (see ~setbordercolor~)
  3432.      The range of overscan register value is 0-255 in VGA+ video adapters.
  3433.  
  3434. % Hardware Compatibility:
  3435.     ■ setpalreg: PCjr,Tandy,EGA,MCGA,VGA and above
  3436.     ■ getpalreg: EGA(with UltraVision v2+), VGA, UltraVision v2+, and above
  3437.  
  3438. % Portability:
  3439.     Will depend most of INT 10h/AX=1000h (for setpalreg) and INT 10h/AX=1007h
  3440.   (for getpalreg) BIOS functions.
  3441.     See also ~Appendix A~ for further information.
  3442.  
  3443. % See Also:
  3444.    Ralf's Brown ~Interrupt List~   ~setbordercolor~    ~getbordercolor~
  3445.    ~setdacreg~    ~getdacreg~
  3446.  
  3447. % Examples:
  3448.     ~Example 5~    ~Example 6~
  3449.  
  3450. %   setpalreg and getpalreg example:
  3451.  
  3452.     To run this example you will need at least a VGA adapter or an EGA adapter
  3453.   with UltraVision v2+.
  3454.  
  3455.  #include <CRT.H>
  3456.  #include <conio.h>
  3457.  
  3458.  void main ()
  3459.   {
  3460.     int a0,a1;
  3461.     fillscr (' ',0x07);
  3462.     printsj ("- - - Hit any key to turn black \
  3463.  into white and write into black - - -",2,0x8f);
  3464.     getch ();
  3465.  
  3466.  //Exchanges palette register 0 and 15 values
  3467.     a0=getpalreg (0);
  3468.     a1=getpalreg (15);
  3469.     setpalreg(0,a1);
  3470.     setpalreg(15,a0);
  3471.     printsj (" - - - Hit any key to unexchange colors - - - ",3,0x83);
  3472.     getch ();
  3473.  
  3474.  //Restores old palette register 0 and 15 values
  3475.     setpalreg(0,a0);
  3476.     setpalreg(15,a1);
  3477.     printsj (" - - - Hit any key to return - - -",24,0x8e);
  3478.     getch ();
  3479.   }
  3480.  
  3481. :setbordercolor:getbordercolor
  3482. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3483. % ▌setbordercolor and getbordercolor▐  <~CRT.H~>
  3484. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3485.     ■ setbordercolor sets overscan color register value.
  3486.     ■ getbordercolor reads overscan color register value.
  3487.  
  3488. % Declaration:
  3489.     ■ void setbordercolor (int val);
  3490.     ■ int  getbordercolor (void);
  3491.  
  3492. % Remarks:
  3493.     ■ setbordercolor uses function INT 10h / AX = 1001h
  3494.     ■ getbordercolor uses function INT 10h / AX = 1008h
  3495.  
  3496.     The value returned by getbordercolor or stored in setbordercolor is the
  3497.   value of overscan color register. This value is the number of a DAC register.
  3498.     The color displayed is given by the DAC register for the overscan color
  3499.   register.
  3500.     The overscan register is not affected by DAC registers paging.
  3501.     BUG: In setbordercolor, the original IBM VGA BIOS incorrectly updates the
  3502.   parameter save area and places the border color at offset 11h of the palette
  3503.   table rather than offset 10h.
  3504.  
  3505. % Hardware Compatibility:
  3506.     ■ setbordercolor: PCjr,Tandy,EGA,VGA and above
  3507.     ■ getbordercolor: EGA(with UltraVision v2+), VGA, UltraVision v2+, and above
  3508.  
  3509. % Portability:
  3510.     Will depend most of INT 10h/AX=1001h (for setbordercolor) and
  3511.   INT 10h/AX=1007h (for getbordercolor) BIOS functions.
  3512.     See also ~Appendix A~ for further information.
  3513.  
  3514. % See Also:
  3515.     Ralf's Brown ~Interrupt List~   ~setpalreg~   ~getpalreg~
  3516.     ~setdacreg~    ~getdacreg~
  3517.  
  3518. % Examples:
  3519.     ~Example 5~
  3520.  
  3521. %   setbordercolor and getbordercolor example:
  3522.  
  3523.     To run this example you will need at least a VGA adapter or an EGA adapter
  3524.   with UltraVision v2+.
  3525.  
  3526.  #include <CRT.H>
  3527.  #include <conio.h>
  3528.  
  3529.  void main ()
  3530.   {
  3531.     int a0;
  3532.     fillscr (' ',0x07);
  3533.     printsj ("- - - Hit any key to change the overscan color - - -",1,0x8f);
  3534.     getch ();
  3535.  
  3536.   //changes the overscan color
  3537.     a0=getbordercolor(); //saves the border color in a0
  3538.     setbordercolor(55); //bordercolor will become light yellow
  3539.  
  3540.     printsj ("- - - Hit any key to restore the overscan color - - -",2,0x8f);
  3541.     getch ();
  3542.  
  3543.   //restores the overscan color
  3544.     setbordercolor(a0);
  3545.  
  3546.     printsj ("- - - Hit any key to continue - - -",3,0x8f);
  3547.     getch ();
  3548.   }
  3549.  
  3550. :setdacreg:getdacreg
  3551. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3552. % ▌setdacreg and getdacreg▐            <~CRT.H~>
  3553. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3554.     ■ setdacreg sets the color of a video DAC register.
  3555.     ■ getdacreg reads the color from a video DAC register.
  3556.  
  3557. % Declaration:
  3558.     ■ void setdacreg (int dacreg, char red, char green, char blue);
  3559.     ■ void getdacreg (int dacreg, char *red, char *green, char *blue);
  3560.  
  3561. % Remarks:
  3562.     dacreg is the DAC register (0-255) and red, green, blue are the red, green
  3563.   and blue values to be loaded or read from the DAC register. The range of
  3564.   red/green/blue (rgb) values is 0(darkest) to 63(lightest), allowing 256k
  3565.   different colors.
  3566.     dacreg range is 0 to 255.
  3567.  
  3568.     ■ setdacreg uses INT 10h/AX=1010h
  3569.     ■ getdacreg uses INT 10h/AX=1015h
  3570.  
  3571. % Hardware Compatibility:
  3572.     ■ setdacreg: MCGA, VGA or above
  3573.     ■ getdacreg: MCGA, VGA or above
  3574.  
  3575. % Portability:
  3576.     Will depend most of INT 10h
  3577.   See also ~Appendix A~ for further information.
  3578.  
  3579. % See Also:
  3580.     Ralf's Brown ~Interrupt List~          ~setpalreg~    ~getpalreg~
  3581.     ~setbordercolor~     ~getbordercolor~    ~setdacpage~   ~setdacpgmode~
  3582.     ~getdacpgstate~
  3583.  
  3584. % Examples:
  3585.     ~Example 6~
  3586.  
  3587. %   setdacreg and getdacreg example:
  3588.  
  3589.     To run this example you will need at least a VGA or MCGA adapter. Works
  3590.   fine in a SVGA or better adapter.
  3591.  
  3592.  #include <CRT.H>
  3593.  #include <conio.h>
  3594.  
  3595.  // This program replaces the black color temporarily by another, by
  3596.  // replacing the DAC register 0 value and restoring it's old value after.
  3597.  // The DAC register 0 usually is selected by palette register 0(black)
  3598.  
  3599.  void main ()
  3600.   {
  3601.     char red,green,blue;
  3602.  
  3603.     fillscr ('.',0x07);
  3604.     prints ("Hit any key to change  the black color",5,1,0x0f);
  3605.     getch ();
  3606.  
  3607.     getdacreg (0,&red,&green,&blue); //saves old values in red,green,blue
  3608.     setdacreg (0,12,0,24); //changes the black color (DAC register 0)
  3609.     prints ("restore",20,1,0x0f);
  3610.     getch ();
  3611.  
  3612.     setdacreg (0,red,green,blue); //restores the color
  3613.     prints ("return.................",20,1,0x0f);
  3614.     getch ();
  3615.   }
  3616.  
  3617. :pgmode:DACPAGE_64:DACPAGE_16
  3618. %   setdacpgmode pgmode argument
  3619. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3620.  
  3621.   The values for pgmode are:
  3622.  
  3623.      value  │ Symbolic Constants │ number of pages (n) │ size of each page*
  3624.     ════════╪════════════════════╪═════════════════════╪═══════════════════
  3625.        0    │ DACPAGE_64         │          4          │       64
  3626.        1    │ DACPAGE_16         │         16          │       16
  3627.  
  3628.     * Number of DAC registers per page.
  3629.  
  3630. % See Also:
  3631.     ~setdacpgmode~
  3632.  
  3633. :setdacpage:setdacpgmode:getdacpgstate
  3634. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3635. % ▌setdacpage, setdacpgmode▐           <~CRT.H~>
  3636. % ▌ and getdacpgstate      ▐
  3637. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3638.     ■ setdacpage selects video DAC color page
  3639.     ■ setdacpgmode selects video DAC paging mode
  3640.     ■ getdacpgstate gets current video DAC page and paging mode.
  3641.  
  3642. % Declaration:
  3643.     ■ void setdacpage(int page);
  3644.     ■ void setdacpgmode (int pgmode);
  3645.     ■ int  getdacpgstate (void);
  3646.  
  3647. % Remarks:
  3648.     In VGA/SVGA and better adapters the 256 DAC register are grouped in (n)
  3649.   pages, each with (x) DAC register. (n) may be 4 or 16. If n==4,x=64 (default).
  3650.   If n==16, x=16.
  3651.     In these adapters, the DAC register for a palette/overscan register
  3652.   is selected by the (6 or 4) least significant bits of it's value plus
  3653.   current video DAC color page times the size (in DAC registers) of a page.
  3654.     setdacpage set's the current video DAC color page ((0-3) if each page
  3655.   has 64 DAC regs, or (0-15) if each page has 16 DAC regs.
  3656.     sedacpgmode set's the number of pages and the number of DAC registers
  3657.   per page, according to ~pgmode~ value.
  3658.  
  3659.     getdacpgstate returns the current video DAC page and paging mode in a word.
  3660.   In this word bits (15-8) gives the current page and bits (7-0) returns
  3661.   current paging mode. The values for paging mode are the same of pgmode
  3662.   (see table above)
  3663.   Summarizing: getdacpgstate()/256 returns the current DAC page number.
  3664.                getdacpgstate()%256 returns current paging mode.
  3665.  
  3666. % Hardware Compatibility:
  3667.     All functions: VGA/SVGA and better
  3668.  
  3669. % Portability:
  3670.     Will depend most of INT 10h
  3671.   See also ~Appendix A~ for further information.
  3672.  
  3673. % See Also:
  3674.    Ralf's Brown ~Interrupt List~             ~setpalreg~   ~getpalreg~
  3675.    ~setbordercolor~     ~getbordercolor~       ~setdacreg~   ~getdacreg~
  3676.  
  3677. % Examples:
  3678.     ~Example 6~
  3679.  
  3680. %   setdacpage,setdacpgmode and getdacpgstate example:
  3681.  
  3682.  #include <CRT.H>
  3683.  #include <conio.h>
  3684.  
  3685.  //   dispmsg displays the value returned by getdacpgstate, current video DAC
  3686.  //color page and video DAC paging mode
  3687.  void dispmsg (void)
  3688.   {
  3689.     unsigned int a0=getdacpgstate
  3690.      ();
  3691.     printsjf (1,0x0f,"getdacpgstate returned %.4Xh.  Video DAC color-page \
  3692.  = %.2Xh.  Paging mode = %.2Xh.",a0,a0/0x100,a0%0x100);
  3693.     getch ();
  3694.   }
  3695.  
  3696.  void main ()
  3697.   {
  3698.     fillscr (' ',7); //clears the screen
  3699.     dispmsg ();
  3700.     setdacpgmode (DACPAGE_16); //sets video DAC paging mode to 1
  3701.     dispmsg ();
  3702.     setdacpage (1); //selects video DAC page 1
  3703.     dispmsg ();
  3704.     setdacpage (3);
  3705.     dispmsg ();
  3706.     setdacpgmode (DACPAGE_64); //sets video DAC paging mode to 0 (VIDEO default)
  3707.     setdacpage (0); //selects video DAC page 0 (VIDEO default)
  3708.     dispmsg ();
  3709.   }
  3710.  
  3711. :setchrboxwidth
  3712. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3713. % ▌setchrboxwidth▐                     <~CRT.H~>
  3714. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3715.     Changes the character box width in VGA or better monitors.
  3716.  
  3717. % Declaration:
  3718.     void setchrboxwidth (int cmd);
  3719.  
  3720. % Remarks:
  3721.     if cmd == 0, boxwidth set's the character box width to be 9.
  3722.     if cmd == 1, boxwidth set's the character box width to be 8.
  3723.     if cmd == 2, boxwidth set's the character box width to be 8
  3724.   if it was 9 and vice versa.
  3725.     boxwidth works only in modes (0,1,2,3 and 7 (including extensions
  3726.   of these modes with more lines)).
  3727.  
  3728.     The video adapter base address is given by ~crt_EVGA_addr~. It's default
  3729.   value is 3C0h. If you are using a alternate VGA adapter, change this value
  3730.   to 2C0h (alternate EGA/VGA)
  3731.  
  3732.     Use this function with care, I can't guarantee that it will work fine in
  3733.   your system.
  3734.  
  3735. % Return Value:
  3736.     None.
  3737.  
  3738. % Hardware Compatibility:
  3739.     VGA, SVGA or better.
  3740.  
  3741. % Portability:
  3742.     See ~Appendix A~.
  3743.  
  3744. % See Also:
  3745.     Ralf's Brown ~Interrupt List~    PC Ports 03C4h,03C5h,03CCh,03C2h
  3746.  
  3747. % Example:
  3748.  
  3749.  #include <CRT.H>
  3750.  #include <conio.h>
  3751.  
  3752.  void main ()
  3753.   {
  3754.     fillscr ('░',0x19);
  3755.     setchrboxwidth (0);
  3756.     getch ();
  3757.     setchrboxwidth (1);
  3758.     getch ();
  3759.     setchrboxwidth (2);
  3760.     getch ();
  3761.     setchrboxwidth (2);
  3762.     getch ();
  3763.     setchrboxwidth (0);
  3764.     getch ();
  3765.   }
  3766.  
  3767. :settextblink
  3768. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3769. % ▌settextblink▐                       <~CRT.H~>
  3770. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3771.     Toggles color/attribute intensity/blinking bit.
  3772.  
  3773. % Declaration:
  3774.     void settextblink (int cmd);
  3775.  
  3776. % Remarks:
  3777.     if cmd==0 instructs video adapter to use color bit 7 as background
  3778.   intensity bit
  3779.     if cmd==1 instructs video adapter to use color bit 7 as text blink
  3780.   enable bit (default)
  3781.     if cmd>1 or cmd<0 the call to textblink is ignored.
  3782.  
  3783.     To get the state of color bit 7, bit 5 of 0040h:0065h indicates the state.
  3784.  
  3785.     textblink uses INT 10h / AX=1003h
  3786.  
  3787. % Return Value:
  3788.     None.
  3789.  
  3790. % Hardware Compatibility:
  3791.     Jr, PS, TANDY 1000, EGA, VGA or better.
  3792.  
  3793. % Portability:
  3794.     See ~Appendix A~.
  3795.  
  3796. % See Also:
  3797.     ~Appendix B~
  3798.  
  3799. % Examples:
  3800.  
  3801.  #include <CRT.H>
  3802.  #include <conio.h>
  3803.  
  3804.  void main ()
  3805.   {
  3806.     //message
  3807.     fillscr (' ',0x07);
  3808.     printsj ("Hit any key to toggle color bit 7 between blink/intensity bit",
  3809.        1,0x8F);
  3810.     getch ();
  3811.  
  3812.     settextblink (0); //define color bit 7 as background intensity bit
  3813.     printsj ("Hit any key to return to normal",2,0x8e);
  3814.     getch ();
  3815.  
  3816.     settextblink (1); //define color bit 7 as blink enable bit (default)
  3817.     printsj ("Hit any key to return",3,0x0f);
  3818.     getch ();
  3819.   }
  3820.  
  3821. %   Another example:
  3822.  
  3823.  #include <CRT.H>
  3824.  #include <conio.h>
  3825.  
  3826.  void dispmsg ()
  3827.     //displays the value stored at 0040:0065h and bit 5 of this value
  3828.   {
  3829.     int a0;
  3830.     a0=*(char far*)0x00400065L;
  3831.     printsf (10,10,0x07,"Contents of memory position 0040:0065h = %.2Xh. \
  3832.  (bit 5) = %d", a0,(a0&0x20)/0x20);
  3833.     getch ();
  3834.   }
  3835.  
  3836.  void main ()
  3837.   {
  3838.     //message
  3839.     fillscr (' ',0x07);
  3840.     printsj ("Hit any key to toggle color bit 7 between blink/intensity bit",
  3841.        1,0x8F);
  3842.     dispmsg(); //displays the value stored at 0040:0065h
  3843.                //and bit 5 of this value
  3844.  
  3845.     settextblink (0); //define color bit 7 as background intensity bit
  3846.     printsj ("Hit any key to return to normal",2,0x8e);
  3847.     dispmsg();
  3848.  
  3849.     settextblink (1); //define color bit 7 as blink enable bit (default)
  3850.     printsj ("Hit any key to return",3,0x0f);
  3851.     dispmsg();
  3852.   }
  3853.  
  3854. :changechar_func:CHANGCHR_NORM:CHANGCHR_RECALC
  3855. %   changechar_func                    <CRT.H>
  3856. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3857.  
  3858.     changechar_func defines the INT 10h function that is going to be used by
  3859.   ~changechar~, the valid values are:
  3860.  
  3861.     Symbolic Constant│ Value │ changechar operation
  3862.     ═════════════════╪═══════╪══════════════════════════════
  3863.      CHANGCHR_NORM   │ 1100h │ only replaces text mode font. (default)
  3864.                      │       │
  3865.      CHANGCHR_RECALC │ 1110h │ replaces text mode font, recalculating character
  3866.                                box height, number of display rows and CRT
  3867.                                buffer length. CRTC registers are reprogrammed.
  3868.                                (page 0 must be active)
  3869.                                (meant to be called immediately after a mode set)
  3870.  
  3871. :changechar_height:changechar_blk
  3872. %   changechar_height and changechar_blk       <CRT.H>
  3873. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3874.  
  3875.     These global variables are used by ~changechar~ and ~changecharg~
  3876.  
  3877.     changechar_height defines the height of characters (in pixels) and the
  3878.   size of each character pattern(in bytes) in call to changechar or
  3879.   changecharg.
  3880.  
  3881.     changechar_blk defines the block to load in map 2. (changechar only)
  3882.  
  3883.  
  3884. :changechar:changecharg
  3885. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3886. % ▌changechar and changecharg▐         <~CRT.H~>
  3887. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3888.     ■ changechar replaces text mode character patterns with user specified
  3889.       patterns
  3890.     ■ changecharg replaces graphics mode character patterns with user
  3891.       specified patterns
  3892.  
  3893. % Declaration:
  3894.     ■ void changechar (unsigned char *fmt, int ind, int qt);
  3895.     ■ void changecharg (unsigned char *fmt, int rows);
  3896.  
  3897. % Remarks:
  3898.     (fmt) is the buffer that holds the user specified patterns.
  3899.     (ind) is the index of the first character that has it's pattern changed
  3900.     (qt) is the count of patterns to store (starting at character (ind))
  3901.     (rows) number of rows.
  3902.     In text mode, changecharg sets the number of scroll lines to (rows)
  3903.  
  3904.     changechar is also affected by changechar_func, changechar_height and
  3905.   changechar_blk global variables.
  3906.  
  3907.     ~changechar_func~ defines the operation of changechar.
  3908.       (you must see ~changechar_func~)
  3909.  
  3910.     ~changechar_height~ defines the character height.
  3911.  
  3912.     ~changechar_blk~ defines the block to load in map 2.
  3913.  
  3914.   Use changechar with changechar_func==CHANGCHR_RECALC if you want to change
  3915.   current character height and number of screen rows. When calling changechar
  3916.   with changechar_func == CHANGCHR_RECALC, page 0 must be active.
  3917.  
  3918.     If changechar_func value is incorrect, the call to changechar is ignored.
  3919.   This is to avoid the possibility of calling wrong INT 10 functions.
  3920.  
  3921.     changecharg is only affected by changechr_height global variable.
  3922.  
  3923.     changechar causes a mode set, completely resetting the video environment,
  3924.   but without clearing the video buffer.
  3925.  
  3926.     changechar and changecharg are designed to be called immediately after a
  3927.   mode set.
  3928.  
  3929.    ■changechar uses INT 10h/AX=changechar_func
  3930.    ■changecharg uses INT 10h/AX=1121h
  3931.  
  3932. % Hardware Compatibility:
  3933.     Both functions: PS, EGA, VGA, SVGA or better.
  3934.  
  3935. % Portability:
  3936.     Will depend most of INT 10h
  3937.   See also ~Appendix A~ for further information.
  3938.  
  3939. % See Also:
  3940.     Ralf's Brown ~Interrupt List~
  3941.  
  3942. % Examples:
  3943.      ~changechar example~         ~changecharg example~
  3944.  
  3945. :changechar example
  3946. %   changechar example
  3947. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3948.  
  3949.  #include <CRT.H>
  3950.  #include <conio.h>
  3951.  
  3952.  void main ()
  3953.   {
  3954.     changechar_func=CHANGCHR_NORM; //try also with CHANGCHR_RECALC
  3955.     char newpattern[]={
  3956.  //this array holds the new character patterns for characters: A B C D E F
  3957.   0x00,0x00,0x1C,0x22, 0x42,0x40,0x40,0x40, //Letter A
  3958.   0x40,0x62,0x52,0xCD, 0x00,0x00,0x00,0x00, //Letter A
  3959.   0x00,0x00,0x38,0x44, 0x42,0x44,0x78,0x44, //Letter B
  3960.   0x42,0x42,0x46,0xB9, 0x00,0x00,0x00,0x00, //Letter B
  3961.   0x00,0x00,0x0E,0x11, 0x21,0x20,0x20,0x20, //Letter C
  3962.   0x20,0x20,0x50,0x8F, 0x00,0x00,0x00,0x00, //Letter C
  3963.   0x00,0x00,0x80,0xC4, 0x4A,0x4A,0x4A,0x4A, //Letter D
  3964.   0x42,0x42,0x46,0xF9, 0x00,0x00,0x00,0x00, //Letter D
  3965.   0x00,0x00,0x3C,0x42, 0x42,0x40,0x30,0x40, //Letter E
  3966.   0x40,0x40,0x42,0x3D, 0x00,0x00,0x00,0x00, //Letter E
  3967.   0x00,0x00,0x43,0x3F, 0x02,0x02,0x42,0x3F, //Letter F
  3968.   0x02,0x02,0x46,0x39, 0x00,0x00,0x00,0x00, //Letter F
  3969.     }; //each row is the pattern for a character
  3970.  
  3971.     setcrtmode (3);
  3972.     fillscr (' ',0x07);
  3973.     prints("Hit any key to change the following characters: @ A B C D E F G",
  3974.        10,1,0x0f);
  3975.     getch ();
  3976.  
  3977.     changechar (newpattern, 0x41, 6); //changes the pattern 6 of characters
  3978.        //starting at character A (41h)
  3979.  
  3980.     getch ();
  3981.     setcrtmode (3); //a mode set restores previous character patterns
  3982.   }
  3983.  
  3984. :changecharg example
  3985. %   changechar example
  3986. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3987.  
  3988.  #include <CRT.H>
  3989.  #include <conio.h>
  3990.  #include <stdio.h>
  3991.  
  3992.  void main ()
  3993.   {
  3994.     int k; //user input
  3995.  
  3996.     setcrtmode (3);
  3997.  
  3998.     fillscr (' ',0x07);
  3999.     prints("Hit any key to set the number of scroll lines to 5",10,1,0x0f);
  4000.     getch ();
  4001.  
  4002.     changecharg (NULL, 5); //changes graphics character to contents of NULL
  4003.       //pointer (interrupt vectors). In text mode set the number of scroll
  4004.       //lines to 5
  4005.  
  4006.    //Writes on screen what user types, until user hits ESC key
  4007.     prints ("To exit hit ESC",10,2,0x0f);
  4008.     crt_gotoxy (0,3);
  4009.     do
  4010.      {
  4011.        k=getch ();
  4012.        if (k==0x0d)
  4013.         {
  4014.           putchar (k);
  4015.           putchar (0x0a);
  4016.         }
  4017.         else
  4018.           putchar(k);
  4019.      }
  4020.      while (k!=0x1b);
  4021.  
  4022.     setcrtmode (3); //a mode set restores default number of scroll lines
  4023.   }
  4024.  
  4025. :moldura:moldurad
  4026. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4027. % ▌moldura and moldurad▐               <~CRT.H~>
  4028. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4029.  
  4030.    ■ moldura is a macro that draws a frame with single outline.
  4031.    ■ moldurad is a macro that draws a frame with double outline.
  4032.  
  4033. % Declaration:
  4034.    ■ void moldura  (xi,yi,xf,yf,color);
  4035.    ■ void moldurad (xi,yi,xf,yf,color);
  4036.  
  4037. % Remarks:
  4038.     Both macros use function ~crtframe~. Their definition are:
  4039.        moldura(xi,yi,xf,yf,color)    => crtframe(xi,yi,xf,yf,color,0)
  4040.        moldurad(xi,yi,xf,yf,color)   => crtframe(xi,yi,xf,yf,color,1)
  4041.  
  4042.     The frame coordinates are given by (xi,yi) and (xf,yf).
  4043.     Their name comes from Portuguese language, where "moldura" means frame.
  4044.   The letter d in front of moldurad stands for "duplo" (double).
  4045.  
  4046. % Return Value:
  4047.     None.
  4048.  
  4049. % Portability:
  4050.     See ~Appendix A~.
  4051.  
  4052. % See Also:
  4053.     ~crtframe~    ~mkline~    ~linha...~    ~molduraw~    ~molduradw~
  4054.  
  4055. % Examples:
  4056.     ~Example 2~
  4057.  
  4058. %  moldura and moldurad example:
  4059.  
  4060.  #include <CRT.H>
  4061.  
  4062.  void main ()
  4063.   {
  4064.     moldura (10,5,30,15,0x0a); //draws the first box frame
  4065.     moldurad (50,5,70,15,0x0b); //draws the second box frame
  4066.   }
  4067.  
  4068. :molduraw:molduradw
  4069. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4070. % ▌molduraw and molduradw▐             <~CRT.H~>
  4071. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4072.  
  4073.    ■ moldura is a macro that draws a frame with single outline.
  4074.    ■ moldurad is a macro that draws a frame with double outline.
  4075.  
  4076. % Declaration:
  4077.    ■ void molduraw  (color);
  4078.    ■ void molduradw (color);
  4079.  
  4080. % Remarks:
  4081.     Both macros uses function ~crtframew~. Their definition are:
  4082.        molduraw(color)    => crtframew(color,0)
  4083.        molduradw(color)   => crtframew(color,1)
  4084.  
  4085.     The frame coordinates are given by ~crtwin_dta~
  4086.  
  4087. % Return Value: none.
  4088.  
  4089. % Portability:
  4090.     See ~Appendix A~.
  4091.  
  4092. % See Also:
  4093.     ~crtframew~   ~crtwin_dta~   ~mkline~   ~linha...~   ~moldura~   ~moldurad~
  4094.  
  4095. % Example:
  4096.  
  4097.  #include <CRT.H>
  4098.  
  4099.  void main ()
  4100.   {
  4101.     setcrtwin (10,5,30,15);
  4102.     molduraw (0x0e); //draws the first box frame
  4103.  
  4104.     crtwin_dta.left+=40;
  4105.     crtwin_dta.right+=40;
  4106.     molduradw (0x0f); //draws the second box frame
  4107.   }
  4108.  
  4109. :linha_hor:linha_ver:linhad_hor:linhad_ver:linha...
  4110. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4111. % ▌linha_hor,     linha_ver,▐          <~CRT.H~>
  4112. % ▌linhad_hor and linhad_ver▐
  4113. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4114.  
  4115.    ■ linha_hor  draws a horizontal line with single outline.
  4116.    ■ linha_ver  draws a vertical line with single outline.
  4117.    ■ linhad_hor draws a horizontal line with double outline.
  4118.    ■ linhad_ver draws a vertical line with double outline.
  4119.   All these macros use automatic frame character replacement algorithm.
  4120.  
  4121. % Declaration:
  4122.  
  4123.    ■ void linha_hor  (y,xi,xf,color);
  4124.    ■ void linha_ver  (x,yi,yf,color);
  4125.    ■ void linhad_hor (y,xi,xf,color);
  4126.    ■ void linhad_ver (x,yi,yf,color);
  4127.  
  4128. % Remarks:
  4129.     These macros have been created to make easy ~mkline~ use. They are defined
  4130.  as follows:
  4131.  
  4132.     linha_hor(y,xi,xf,color)   => mkline(y,xi,xf,color,0)
  4133.     linha_ver(y,xi,xf,color)   => mkline(y,xi,xf,color,1)
  4134.     linhad_hor(y,xi,xf,color)  => mkline(y,xi,xf,color,2)
  4135.     linhad_ver(y,xi,xf,color)  => mkline(y,xi,xf,color,3)
  4136.  
  4137.     They are useful to build divisions or lines inside text boxes, text frames
  4138.   and anywhere else.
  4139.     The name "linha" comes from Portuguese. "Linha" means line
  4140.     Further information is available in ~mkline~ and ~mkline_aux~
  4141.  
  4142. % Return Value:
  4143.     None.
  4144.  
  4145. % Portability:
  4146.     See ~Appendix A~.
  4147.  
  4148. % See Also:
  4149.     ~moldura~     ~moldurad~     ~molduraw~     ~molduradw~
  4150.  
  4151. % Examples:
  4152.     ~Example 2~
  4153.  
  4154. %  linha_hor, linha_ver, linhad_hor and linhad_ver example:
  4155.  
  4156.  #include <CRT.H>
  4157.  
  4158.  void main ()
  4159.   {
  4160.     moldura (10,5,30,15,0x0f); //draws the first box frame
  4161.     linha_hor (10,10,30,0x0f); //and create divisions inside
  4162.     linha_ver (20,5,15,0x0f); //the box
  4163.  
  4164.     moldurad (50,5,70,15,0x0e); //draws the second box frame
  4165.     linhad_hor (10,50,70,0x0e); //and create divisions inside
  4166.     linhad_ver (60,5,15,0x0e); //the box
  4167.   }
  4168.  
  4169.   See also example 2 at the end of file.
  4170.  
  4171.  
  4172. :janela:janelad
  4173. % ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4174. % ▌janela and janelad ▐                <~CRT.H~>
  4175. % ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4176.  
  4177.    ■ janela is a macro that draws a text box with single outline.
  4178.    ■ janelad is a macro that draws a text box with double outline.
  4179.  
  4180. % Declaration:
  4181.    ■ void janela   (struct ~crtwin_inp~ p0);
  4182.    ■ void janelad  (struct crtwin_inp p0);
  4183.  
  4184. % Remarks:
  4185.     Both macros use function ~crtwindow~. Their definition are:
  4186.        janela(p0)              =>    p0.type=0;
  4187.                                      crtwindow(p0);
  4188.  
  4189.        janelad(p0)             =>    p0.type=1;
  4190.                                      crtwindow(p0);
  4191.  
  4192.     As you can see above these macros changes p0.
  4193.  
  4194. % Return Value:
  4195.     None.
  4196.  
  4197. % Portability:
  4198.     See ~Appendix A~.
  4199.  
  4200. % Example:
  4201.     ~Example 3~
  4202.  
  4203. :setcrtwin
  4204. % ▄▄▄▄▄▄▄▄▄▄▄▄
  4205. % ▌setcrtwin ▐                         <~CRT.H~>
  4206. % ▀▀▀▀▀▀▀▀▀▀▀▀
  4207.     setcrtwindow is a macro defined to make easy the work of assigning values
  4208.  for ~crtwin_dta~ global variable.
  4209.  
  4210. % Declaration:
  4211.    ■ void setcrtwin   (int xi, int yi, int xf, int yf);
  4212.  
  4213. % Remarks:
  4214.     This macro is the same as the lines below
  4215.        crtwin_dta.left=xi;
  4216.        crtwin_dta.top=yi;
  4217.        crtwin_dta.right=xf;
  4218.        crtwin_dta.bottom=yf;
  4219.  
  4220. % Return Value:
  4221.     None.
  4222.  
  4223. % Portability:
  4224.     See ~Appendix A~.
  4225.  
  4226. % Examples:
  4227.     ~Example 3~
  4228.  
  4229. :Example 1
  4230. %   CRT.H functions Example 1
  4231. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4232.  
  4233.  
  4234.  #include <CRT.H>
  4235.  #include <conio.h>
  4236.  #include <stdio.h>
  4237.  
  4238.  void main ()
  4239.   {
  4240.     textmode (3);
  4241.     fillscr ('░',0x19);
  4242.        //fills the screen with character ░ and color 19h
  4243.  
  4244.     prints ("* * * CRT FUNCTIONS EXAMPLE n. 1 * * *",21,0,0x1f);
  4245.        //this is a prints example
  4246.     getch ();//pauses
  4247.  
  4248.     printsn ("TEXT ONLY OUTPUT - PRINTSN",10,2);
  4249.     getch ();
  4250.  
  4251.     printxy ("PRINTXY EXAMPLE",10,5,2,1,0x20);
  4252.     getch ();
  4253.  
  4254.     printc ('0',79,0,0x3f);
  4255.        //writes 0 at upper right corner with a write color and cyan background
  4256.     getch ();
  4257.  
  4258.     printcn ('M',79,1); //the same as printc, but with no color. Outputs
  4259.        //letter 'M' just below the '0'
  4260.     getch ();
  4261.  
  4262.     changecolor (79,2,0x1f); //replaces the color at position (79,2) for (1F)h
  4263.        //write with a blue background
  4264.     getch ();
  4265.  
  4266.   //getcrtchar and getcrtcolor example
  4267.     printsf(10,10,0x1e,"The character at position (79,0) is '%c' and it's color\
  4268.   is (%x)h", getcrtchar (79,0),getcrtcolor (79,0));
  4269.     //printsf is a kind o printf that uses prints to output formatted string
  4270.     getch ();
  4271.  
  4272.     prints ("- - - Hit any key to return - - -",23,24,0x9e);
  4273.        //colors greater than 80h are usually blinking in DOS full screen,
  4274.        //but aren't in DOS window mode (WINDOWS)
  4275.  
  4276.     getch ();
  4277.     //the lines below are equivalent to clrscr();
  4278.     crt_gotoxy (0,0);
  4279.     fillscr (' ',0x07);
  4280.   }
  4281.  
  4282. :Example 2
  4283. %   CRT.H functions Example 2
  4284. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4285.  
  4286.  
  4287.  #include <CRT.H>
  4288.  #include <conio.h>
  4289.  //crtframe, mkline, and macros examples.
  4290.  //This example contains many sub-examples. Perhaps it is interesting
  4291.  //to separate them.
  4292.  
  4293.  void main ()
  4294.   {
  4295.     int i=0,j=0,k=0;
  4296.  
  4297.  //crtframe and mkline macros examples
  4298.  
  4299.     fillscr ('░',0x19);
  4300.     prints ("* * * fillbar, crtframe and mkline example * * *",16,1,0x1e);
  4301.     prints ("Using macros moldura... and linha_...",21,2,0x1f);
  4302.  
  4303.     moldura (10,5,30,13,0x1f);
  4304.     getch ();
  4305.     fillbar ('.',11,6,29,12,0x19);
  4306.     getch ();
  4307.     fillbar ('·',51,6,69,12,0x19);
  4308.     getch ();
  4309.     moldurad (50,5,70,13,0x1f);
  4310.     getch ();
  4311.  
  4312.     linha_hor (9,10,30,0x1e);
  4313.     getch ();
  4314.     linhad_hor (9,50,70,0x1e);
  4315.     getch ();
  4316.     linha_ver (20,5,13,0x1e);
  4317.     getch ();
  4318.     linhad_ver (60,5,13,0x1e);
  4319.     getch ();
  4320.     prints ("- - - Hit any key to continue - - -",22,24,0x9e);
  4321.     getch ();
  4322.  
  4323.  //crtframe example
  4324.  
  4325.     fillscr ('░',0x19);
  4326.     prints ("* * * Example of any frames draw by crtframe * * *",15,1,0x1e);
  4327.     getch ();
  4328.  
  4329.     crtframe (10,5,20,8,0x1f,0);
  4330.     prints ("type = 0",11,9,0x1f);
  4331.     getch ();
  4332.  
  4333.     crtframe (37,5,47,8,0x1f,1);
  4334.     prints ("type = 1",38,9,0x1f);
  4335.     getch ();
  4336.  
  4337.     crtframe (63,5,73,8,0x1f,2);
  4338.     prints ("type = 2",64,9,0x1f);
  4339.     getch ();
  4340.  
  4341.     crtframe (10,15,20,18,0x1f,3);  //default user defined character='█'
  4342.     prints ("type = 3",12,19,0x1f);
  4343.     getch ();
  4344.  
  4345.     crtframe (37,15,47,18,0x1f,'■\1');
  4346.       //user defined character is redefined as'■'
  4347.     prints ("type = 1FEh",37,19,0x1f);
  4348.     getch ();
  4349.  
  4350.     crtframe (63,15,73,18,0x1f,3);  //current user defined character='■');
  4351.     prints ("type = 3",64,19,0x1f);
  4352.     getch ();
  4353.  
  4354.  /*
  4355.  Remark: Compiler details (Borland's Turbo C++ 3.0)
  4356.  'a0' is the same as 0x3061 where 30h and 61 are the ASCII code of '0' and 'a'
  4357.  respectively
  4358.  'a0' can also be represented by 'a\x30' or 'a\60' or 0x3061 or ...
  4359.  '■\1' is the same as 0x01FE
  4360.  'a' is the same as 'a\0' = 0x0061. But (for values greater than 7Fh)
  4361.  '■' is the same as '■\xff'= 0xfffe that is different from 0x00FE = '■\0'
  4362.  */
  4363.  
  4364.  //crtframe and mkline example
  4365.  
  4366.     #define L0 18     //column initial position
  4367.     #define L1 5      //row (line) initial position
  4368.     #define L2 8      //each x side size
  4369.     #define L3 6      //each y side size
  4370.     #define L4 4      //x median
  4371.     #define L5 3      //y median
  4372.     #define L6 10     //smaller spacing in x
  4373.     #define L7 8      //spacing in y
  4374.     #define L8 24     //bigger spacing in x
  4375.     #define CF 0x1e
  4376.     #define CL 0x1f
  4377.  
  4378.     fillscr ('░',0x19);
  4379.     prints ("* * * FRAME TYPES * * *",28,1,0x1e);
  4380.     prints ("Using crtframe and mkline",27,3,0x1b);
  4381.     for (i=0;i<2;i++)
  4382.        for (j=0;j<2;j++)
  4383.           for (k=0;k<2;k++)
  4384.            {
  4385.              crtframe (L0+L6*k+L8*i,L1+L7*j,L0+L2+L6*k+L8*i,L1+L3+L7*j,CF,i);
  4386.              mkline(L1+L5+L7*j,L0+L6*k+L8*i,L0+L2+L6*k+L8*i,CL,2*k);
  4387.              mkline(L0+L4+L6*k+L8*i,L1+L7*j,L1+L3+L7*j,CL,2*j+1);
  4388.            }
  4389.     getch ();
  4390.     prints ("- - - Hit any key to return - - -",23,24,0x9f);
  4391.     getch();
  4392.     crt_gotoxy (0,0); //clears the screen and moves the cursor to upper
  4393.     fillscr (' ',0x07); //left corner => these two functions together are
  4394.                         //similar to clrscr
  4395.   }
  4396.  
  4397.  
  4398. :Example 3
  4399. %   CRT.H functions Example 3
  4400. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4401.  
  4402.  
  4403.  #include <CRT.H>
  4404.  #include <conio.h>
  4405.  
  4406.  //symbolic constants
  4407.  #define LEFT_TEXT 0
  4408.  #define CENTER_TEXT 1
  4409.  #define RIGHT_TEXT 2
  4410.  
  4411.  void main ()
  4412.   {
  4413.     struct crtwin_inp licos;
  4414.     textmode(3);
  4415.     fillscr ('░',0x19);
  4416.  
  4417.  //setcrtwin, janela and janelad examples
  4418.  
  4419.  // setcrtwin(-1,-1,80,25); default
  4420.     printsj ("* * * MACRO EXAMPLES * * *",0,0x1f);
  4421.     licos.title="JANELA EXAMPLE";//if licos.title==NULL doesn't output
  4422.                                  //title nor left space for it.
  4423.     licos.tcolor=0x1f;
  4424.     licos.fchr='░';
  4425.     licos.fcolor=0x13;
  4426.     licos.bcolor=0x1e;
  4427.     setcrtwin(5,5,35,13);
  4428.     //licos.btype=0; =>done by janela macro
  4429.     janela (licos);
  4430.     getch();
  4431.     setcrtwin(45,5,75,13);
  4432.     licos.title="JANELAD EXAMPLE";
  4433.     //licos.btype=1; =>done by janelad macro
  4434.     janelad (licos);
  4435.     setcrtwin(-1,-1,80,25);
  4436.     printsj("- - - Hit any key to continue - - -",24,0x9e);
  4437.     getch ();
  4438.  
  4439.  //crtwindow and printsj example
  4440.     int c0;
  4441.     struct crtwin_inp lelecos[4]={
  4442.  {"WINDOW 1",0x1f,'░',0x13,0x1e,0},//lelecos[0] declaration
  4443.  {"WINDOW 2",0x1f,'░',0x13,0x1e,1},//lelecos[1] declaration
  4444.  {"WINDOW 3",0x1f,'░',0x13,0x1e,2},//lelecos[2] declaration
  4445.  {"WINDOW 4",0x1f,'.',0x13,0x1e,'■\1'}//lelecos[3] declaration
  4446.  //key to each line:
  4447.  //{(title),(title color),(chr to fill),(color to fill),(border color),
  4448.  //(border type)},
  4449.  };
  4450.     struct crtwin deflt={-1,-1,80,25};//default values for crtwin_dta
  4451.     struct crtwin kiko[4]={{5,3,35,10},{45,3,75,10},{5,13,35,20},{45,13,75,20}};
  4452.  
  4453.     fillscr ('░',0x19);
  4454.     printsj ("* * * CRTWINDOW EXAMPLE * * *",0,0x1f);
  4455.     for (c0=0;c0<4;c0++)
  4456.      {
  4457.        crtwin_dta=kiko[c0];
  4458.        crtwindow(lelecos[c0]);
  4459.      }
  4460.     crtwin_dta=deflt;//similar to setcrtwin
  4461.     printsj("- - - Hit any key to continue - - -",24,0x9e);
  4462.     getch();
  4463.     setcrtwin(10,0,80,25);
  4464.     printsj ("AND PRINTSJ EXAMPLE",0,0x1f);
  4465.     for (c0=0;c0<4;c0++)
  4466.      {
  4467.        crtwin_dta=kiko[c0];
  4468.        crtwin_just=0; printsj("LEFT TEXT",0,0x1b);
  4469.        crtwin_just=1; printsj("CENTER TEXT",1,0x1f);
  4470.        crtwin_just=2; printsj("RIGHT TEXT",2,0x1e);
  4471.      }
  4472.     crtwin_dta=deflt;
  4473.     crtwin_just=CENTER_TEXT;//or 1
  4474.     printsj("- - - Hit any key to continue - - -",24,0x9e);
  4475.     getch ();
  4476.     fillbar ('░',0,0,79,20,0x19);
  4477.  //hint call twice crtwindow to draw text box with another title format
  4478.     printsj("HINT: call twice crtwindow with different values for p0.btype",
  4479.        0,0x1f);
  4480.     printsj("to obtain this interesting effect in title",1,0x1f);
  4481.     for (c0=0;c0<2;c0++)
  4482.      {
  4483.        crtwin_dta=kiko[c0];
  4484.        crtwindow (lelecos[c0]);
  4485.        getch ();
  4486.        lelecos[c0].btype=0x00ff;
  4487.        crtwindow (lelecos[c0]);
  4488.        getch();
  4489.      }
  4490.  
  4491.  //printtext example
  4492.     crtwin_dta.left=24;
  4493.     crtwin_dta.top=12;
  4494.     crtwin_dta.right=55;
  4495.     crtwin_dta.bottom=20;
  4496.     licos.title="PRINTTEXT EXAMPLE";
  4497.     crtwindow (licos);
  4498.     printtext ("Using printtext you can write texts inside a box",3,1,0x1f);
  4499.     getch ();
  4500.  
  4501.     crtwin_dta=deflt;
  4502.     crtwin_just=CENTER_TEXT;//or 1
  4503.     printsj("  - - - Hit any key to exit - - -  ",24,0x9e);
  4504.     getch ();
  4505.   }
  4506.  
  4507. :Example 4
  4508. %   CRT.H functions Example 4
  4509. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4510.  
  4511.  /* Example of setcrtmode, getcrtmode and setcrtpage */
  4512.  
  4513.  #include <CRT.H>
  4514.  #include <conio.h>
  4515.  #include <dos.h>
  4516.  
  4517.  #define PG 3 //page to select
  4518.     //0-7 for EGA/VGA   and   0-3 for CGA
  4519.  
  4520.  void main ()
  4521.   {
  4522.     int a0;
  4523.  
  4524.     crt_page=10000; //loading crt_page with value that's not actual
  4525.     //notice that this page number is impossible
  4526.  
  4527.     printsjf (1,0x1f,"vmode_mode=%d vmode_x=%d vmode_y=%d crt_page=%d (not a \
  4528.  video page number)",vmode_mode, vmode_x,vmode_y,crt_page);
  4529.     getch ();
  4530.     a0=getcrtmode();
  4531.        //vmode_mode<-current mode   vmode_x<-actual number of columns
  4532.        //crt_page<-actual display page a0<-vmode_mode
  4533.  
  4534.     printsjf (2,0x1f,"crtmode=%d = vmode_mode=%d vmode_x=%d vmode_y=%d \
  4535.  crt_page=%d (current video page)",a0,vmode_mode,vmode_x,vmode_y,crt_page);
  4536.     getch ();
  4537.  
  4538.     setcrtmode (1); //text mode 1
  4539.     a0=getcrtmode();
  4540.     printxf (0,1,0x1f,"crtmode=%d = vmode_mode=%d vmode_x=%d \n\tvmode_y=%d \
  4541.  crt_page=%d",a0,vmode_mode,vmode_x,vmode_y,crt_page);
  4542.     getch ();
  4543.  
  4544.     setcrtmode (3); //text mode 3
  4545.     setcrtpage (PG); //selects page PG
  4546.     printsjf (2,0x1f,"vmode_mode=%d vmode_x=%d vmode_y=%d crt_page=%d \
  4547.  video_addr=%Fp",vmode_mode, vmode_x,vmode_y,crt_page,video_addr);
  4548.     //notice that each page has a different start address, setcrtpage
  4549.     //automatically updates video_addr to page start address.
  4550.     getch ();
  4551.  
  4552.     setcrtpage(0);
  4553.     //selects page 0. video_addr not changed (Reason: no longer used)
  4554.   }
  4555.  
  4556.  
  4557. :Example 5
  4558. %   CRT.H functions Example 5
  4559. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4560.  
  4561.     To run this example you will need at least a VGA adapter or an EGA adapter
  4562.   with UltraVision v2+.
  4563.  
  4564.  #include <CRT.H>
  4565.  #include <conio.h>
  4566.  
  4567.  void main ()
  4568.   {
  4569.     int c0;
  4570.     char oldpalette[16]; //used to store original register palette values
  4571.     int oldbordercolor; //used to store the original overscan register value
  4572.  
  4573.     char newpalette[16]= //new values for the palette
  4574.  // {8,25,0,1, 9,41,57,25, 43,11,17,35, 3,27,31,63}; //blue palette
  4575.     {63,1,13,2, 23,51,60,62, 16,9,38,26, 21,47,46,31};
  4576.     //try also the blue palette.
  4577.  
  4578.     int newbordercolor=8; //new value for overscan register
  4579.  
  4580.   //Draws the presentation screen and displays some important messages
  4581.     fillscr ('░',0x19);
  4582.     printsj ("* * * SETPALREG AND GETPALREG EXAMPLE * * *",0,0x1e);
  4583.     prints ("The current register values are: ",10,2,0x17);
  4584.     fillbar (' ',3,4,32,23,0x17);
  4585.     for (c0=0;c0<16;c0++)
  4586.      {
  4587.        oldpalette[c0]=getpalreg(c0); //saves each palette register in oldpalette
  4588.  
  4589.     //displays each palette register number and it's value (DAC register number)
  4590.        printsf (5,c0+5,0x1f,"register %2d value= %3d ( )",c0,getpalreg(c0));
  4591.        printc ('■',29,c0+5,c0+0x10);
  4592.      }
  4593.     oldbordercolor=getbordercolor(); //saves overscan register in oldbordercolor
  4594.     printsf (4,22,0x1f,"Overscan register value =%3d",oldbordercolor);
  4595.  
  4596.   //Message
  4597.     prints (" - - - Hit any key to - - - ",40,4,0x9b);
  4598.     prints (" - - - change the palette - - -",42,5,0x9b);
  4599.     prints (" - - - and overscan color - - -",44,6,0x9b);
  4600.     getch ();
  4601.  
  4602.   //Changes palette and overscan color
  4603.     for (c0=0;c0<16;c0++)
  4604.        setpalreg (c0, newpalette[c0]); //replaces the value of each palette
  4605.           //register by the value given by newpalette[c0]
  4606.  
  4607.     setbordercolor(newbordercolor); //replaces the value of overscan register
  4608.        //by newbordercolor. If this doesn't work or locks up your system try
  4609.        //using getbordercolor instead.
  4610.  
  4611.   //Updates table in the left side
  4612.     for (c0=0;c0<16;c0++)
  4613.        printsf (24,c0+5,0x1f,"%3d",getpalreg(c0));
  4614.     printsf(29,22,0x1f,"%3d",getbordercolor());
  4615.  
  4616.   //Message
  4617.     prints ("restore the palette - - -",49,5,0x9b);
  4618.     getch ();
  4619.  
  4620.   //Restores old values of palette and overscan registers
  4621.     for (c0=0;c0<16;c0++)
  4622.        setpalreg (c0, oldpalette[c0]); //restores the value of each palette
  4623.           //register
  4624.  
  4625.     setbordercolor (oldbordercolor); //restores the value of overscan register
  4626.        //If this doesn't work or locks up your system try using setbordercolor
  4627.        //instead.
  4628.  
  4629.  
  4630.   //Updates table in the left side
  4631.     for (c0=0;c0<16;c0++)
  4632.        printsf (24,c0+5,0x1f,"%3d",getpalreg(c0));
  4633.     printsf(29,22,0x1f,"%3d",getbordercolor());
  4634.  
  4635.  
  4636.   //Message
  4637.     fillbar ('░',42,5,74,6,0x19);
  4638.     prints (" - - - to exit - - -",42,5,0x9b);
  4639.     getch ();
  4640.   }
  4641.  
  4642. :Example 6
  4643. %   CRT.H functions Example 6
  4644. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4645.  
  4646.     To run this example you will need a VGA adapter or better. Works
  4647.   fine in a SVGA or better adapter.
  4648.  
  4649.  //This program displays the palette register, their values, and allows
  4650.  //you to select one palette register, and change it's value. It displays
  4651.  //also the DAC register of selected palette register, the current DAC
  4652.  //page and paging mode.
  4653.  
  4654.  #include <CRT.H>
  4655.  #include <conio.h>
  4656.  
  4657.  //Displays message about paging mode and current page
  4658.  void dacpagemsg ()
  4659.   {
  4660.     int a0;
  4661.     char *n0,*n1;
  4662.     a0=getdacpgstate();
  4663.     if (a0%256==0) //if paging mode == 0
  4664.      {
  4665.        n0="4"; n1="64";
  4666.      }
  4667.      else if (a0%256) //if paging mode == 1
  4668.      {
  4669.        n0="16"; n1="16";
  4670.      }
  4671.      else //if paging mode != 0 and 1
  4672.      {
  4673.        n0="???"; n1="???";
  4674.      }
  4675.     printsf (40,3,0x0f,"Current page = %d of %s pages.  ",a0/256,n0);
  4676.     printsf (40,4,0x0f,"Each page has %s DAC registers",n1);
  4677.     printsf (40,5,0x0f,"Current paging mode = %d",a0%256);
  4678.   }
  4679.  
  4680.  void main ()
  4681.   {
  4682.     int c0, a0;
  4683.     int red,green,blue;
  4684.     int palettereg=0, paletteval=0, dacpage=0, dacpgmode=0;
  4685.     int k; //input key;
  4686.  // char newpalette[]={0,1,2,3, 20,21,22,23, 40,41,42,43, 60,61,62,63};
  4687.  
  4688.   //message
  4689.     fillscr (' ',0x07);
  4690.     printsj ("- - - Please Wait. Writing DAC registers - - -",12,0x8F);
  4691.  
  4692.   // changes the color of DAC register from 40h through FFh
  4693.     for (c0=64;c0<256;c0++) //changes the color of DAC registers
  4694.        setdacreg (c0,((c0/64)*16)%64,((c0/8)*8)%64,(c0*8)%64);
  4695.  
  4696.   //message
  4697.     fillscr (' ',0x07);
  4698.     prints ("Directions: To change palette register type 1.",0,18,0x0b);
  4699.     prints ("To change palette register value, type 2 or 3.",10,19,0x0b);
  4700.     prints ("To change page, type 4.",10,20,0x0b);
  4701.     prints ("To change paging mode, type 5.",10,21,0x0b);
  4702.     prints ("To change the DAC register which determines the color of",
  4703.        10,22,0x0b);
  4704.     prints ("selected palette register type R or G or B.",10,23,0x0b);
  4705.     prints ("To finish type ESC",10,24,0x0b);
  4706.  
  4707.   //program main loop
  4708.     do
  4709.      {
  4710.        setdacpgmode (dacpgmode); //sets paging mode given by dacpgmode
  4711.        setdacpage (dacpage); //sets DAC page
  4712.        setpalreg (palettereg, paletteval);
  4713.           //changes the value for selected palette register
  4714.  
  4715.       //displays the value of each palette register
  4716.        for (c0=0;c0<16;c0++)
  4717.         {
  4718.           printsf (0,c0+2,0x1f,"register %2d value=%3d ( ) ",c0,getpalreg(c0));
  4719.           printc ('■',23,c0+2,c0+0x10);
  4720.         }
  4721.  
  4722.       //Displays message about paging mode and current page
  4723.        dacpagemsg ();
  4724.  
  4725.       //Displays selected palette register and it's value
  4726.        a0=getpalreg(palettereg); //a0 = palette register value
  4727.        printsf (40,7,0x0f,"Selected palette register = %2d",palettereg);
  4728.        printsf (40,8,0x0f,"Selected palette register value = %3d",a0);
  4729.  
  4730.       //Determines the DAC register which gives the color of selected
  4731.       //palette register
  4732.        if(getdacpgstate()%256==0)
  4733.         {
  4734.           a0%=64;
  4735.           a0+=(getdacpgstate()/256)*64;
  4736.         }
  4737.         else
  4738.         {
  4739.           a0%=16;
  4740.           a0+=(getdacpgstate()/256)*16;
  4741.         }
  4742.  
  4743.       //Displays the number of DAC register which determines the color
  4744.       //of selected palette register.
  4745.        printsf (40,9,0x0f,"Selected palette DAC register = %3d",a0);
  4746.        getdacreg(a0,(char *)&red,(char *)&green,(char *)&blue);
  4747.        printsf (40,10,0x0f,"DAC register %3d color(rgb) = (%2d,%2d,%2d)",a0,
  4748.           red&0x00FF,green&0x00FF,blue&0x00FF);
  4749.  
  4750.       //k <= user input
  4751.        k=getch ();
  4752.        switch (k)
  4753.         {
  4754.           case '1': //selects another palette register
  4755.              palettereg++;
  4756.              palettereg%=16;
  4757.              paletteval=getpalreg(palettereg);
  4758.            break;
  4759.           case '3': //changes palette register value
  4760.              paletteval+=15;
  4761.           case '2': //changes palette register value
  4762.              paletteval++;
  4763.              paletteval%=256;
  4764.            break;
  4765.           case '4': //changes video DAC color page
  4766.              dacpage++;
  4767.              dacpage%=16;
  4768.            break;
  4769.           case '5': //changes video DAC color paging
  4770.              dacpage=0;
  4771.              dacpgmode++;
  4772.              dacpgmode%=2;
  4773.            break;
  4774.           case 'R':
  4775.           case 'r':
  4776.           case 'G':
  4777.           case 'g':
  4778.           case 'B':
  4779.           case 'b':
  4780.            //Changes the DAC register which determines the color
  4781.                  //of selected palette register.
  4782.              if (k=='R')
  4783.                 red+=8;
  4784.              else if (k=='r')
  4785.                 red++;
  4786.              else if (k=='G')
  4787.                 green+=8;
  4788.              else if (k=='g')
  4789.                 green++;
  4790.              else if (k=='B')
  4791.                 blue+=8;
  4792.              else if (k=='b')
  4793.                 blue++;
  4794.              red%=64;
  4795.              green%=64;
  4796.              blue%=64;
  4797.              setdacreg(a0,red,green,blue);
  4798.           break;
  4799.         }
  4800.      }
  4801.      while (k!=0x1b); //if user hits ESC, returns
  4802.  
  4803.     setcrtmode (3); //set video to mode 3, restoring palette and DAC registers
  4804.   }
  4805.  
  4806.  
  4807. :Appendix A
  4808. %   Appendix A: Portability
  4809. %  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4810.  
  4811.     These functions have been developed and tested in MS-DOS operating system
  4812.  versions 6.22 and 7.0, being executed directly or under WINDOWS (3.11 or 95)
  4813.  No compatibility tests with UNIX, ANSI C alone and C++ alone have been done.
  4814.  So I can only speculate if these functions will work fine in other compilers
  4815.  and other operating systems. I suppose that they may work in UNIX only if the
  4816.  hardware and the BIOS are the same of IBM PC machines, perhaps with some
  4817.  restrictions, as some functions (for example printx) uses DOS calls. About
  4818.  compilers, the user may experience some trouble trying to compile in 32 bit
  4819.  mode in newer compilers, in this case you will probably need to change some
  4820.  lines of the source code of these functions to solve some portability
  4821.  problems.
  4822.     At least I know that under Windows some specific hardware functions,
  4823.  as changechar or textblink are not effective in a MS-DOS box. However
  4824.  they are fully effective if MS-DOS is running in full screen mode.
  4825.  
  4826.     If you port these functions to a 32 bit environment, to a 32 bit compiler
  4827.  or to DJGPP, let me know.
  4828.  
  4829.     If you experience some problems (portability, other) report me to
  4830.  jlfialho@iconet.com.br or (alternate) jlfialho@yahoo.com
  4831.     All these functions have been tested in Borland's Turbo C++ 3.0 (1992) in
  4832.  MS-DOS environment. All them have worked fine.
  4833.  
  4834.     * * * IMPORTANT: Test these functions thoroughly if you are going * * *
  4835.     * * * to use them in other environments than specified.           * * *
  4836.  
  4837.    I've tested them a lot and I did them in the best of my ability (in the
  4838.  time I had to do them), but I can't guarantee that there's no bug left or
  4839.  that they will work in systems that I'm not the owner. I believe they are
  4840.  reasonably safe and very hardly would cause problem, but never is too much
  4841.  to check for errors and test them.
  4842.  
  4843. :Appendix B
  4844. %   Appendix B : color Bits
  4845. %  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  4846.  
  4847.     The color or attribute is given in accordance to bits of (color) argument,
  4848. *  which are the same as used by graphics adapters.
  4849.     Usually:
  4850.  
  4851.   color (DOS or WINDOWS DOS prompt in full screen)  => LRGB IRGB
  4852.                                                  background character
  4853.  
  4854.   color (WINDOWS DOS prompt in a DOS box)           => IRGB IRGB
  4855.                                                  background character
  4856.  
  4857.   L = > blinking bit
  4858.   I = > intensity (light/normal)
  4859.   R = > red
  4860.   G = > green
  4861.   B = > blue
  4862.  
  4863.   bit 7=> in full screen mode or real DOS mode it may be character blinking
  4864.   switch (more common) or intensity bit of background color
  4865.   (see ~settextblink~).
  4866.   In a DOS window box (WINDOWS) it is the intensity bit of background color
  4867.   and as I know you can't toggle it between intensity/blink enable bit.
  4868.  
  4869.   bit 6=> red bit of background color.
  4870.   bit 5=> green bit of background color.
  4871.   bit 4=> blue bit of background color
  4872.  
  4873.   bit 3=> intensity bit of foreground color (on full screen mode, it may select
  4874.   a second DOS font)
  4875.   bit 2=> red bit of foreground color.
  4876.   bit 1=> green bit of foreground color.
  4877.   bit 0=> blue bit of foreground color.
  4878.  
  4879.  The bit function is active when it's set (bit==1)
  4880.  The characters are draw with foreground color.
  4881.  
  4882.  
  4883.  Brief description of color and color indexes:
  4884.  
  4885.      index │  index │ index  │
  4886.      (dec) │ (hex)  │ IRGB   │ color description
  4887.     ═══════╪════════╪════════╪═══════════════════════════
  4888.         0  │    0   │ 0000   │black
  4889.         1  │    1   │ 0001   │blue
  4890.         2  │    2   │ 0010   │green
  4891.         3  │    3   │ 0011   │cyan
  4892.         4  │    4   │ 0100   │red
  4893.         5  │    5   │ 0101   │magenta
  4894.         6  │    6   │ 0110   │brown
  4895.         7  │    7   │ 0111   │light gray
  4896.         8  │    8   │ 1000   │dark gray
  4897.         9  │    9   │ 1001   │light blue
  4898.        10  │    A   │ 1010   │light green
  4899.        11  │    B   │ 1011   │light cyan
  4900.        12  │    C   │ 1100   │light red
  4901.        13  │    D   │ 1101   │light magenta
  4902.        14  │    E   │ 1110   │yellow
  4903.        15  │    F   │ 1111   │white
  4904.  
  4905.     These colors can be redefined in a EGA or VGA or better monitor using
  4906.   ~setpalreg~ or ~setdacreg~(VGA,SVGA or better).
  4907.  
  4908.     If you desire you may use combinations of symbolic color constants
  4909.  (~CRT_COLORS~) instead of using numbers. For example:
  4910.     fillscr ('░',BLUE*BKCOLOR+LIGHTGRAY);
  4911.   is the same as:
  4912.     fillscr ('░',0x17);
  4913.  
  4914. % See Also:
  4915.     ~CRT_COLORS~   ~COLORS~   ~textattr~
  4916.  
  4917. :Interrupt List
  4918. %   Ralf's Brown Interrupt List
  4919. %  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  4920.  
  4921.     Ralf's Brown Interrupt List is a listing of PC interrupts with over 2Mb of
  4922.   text. It's available in the following Web Pages:
  4923.     Main site:
  4924.       http://www.cs.cmu.edu/afs/cs/user/ralf/pub/WWW/files.html
  4925.  
  4926.     Alternate Sites:
  4927.       http://www.simtel.net/msdos/info.html
  4928.       http://oak.oakland.edu/msdos/info.html => mirror of Simtel Net
  4929.       ftp://ftp.cdrom.com/pub/simtelnet/msdos/info/interRRA.ZIP
  4930.                                                    interRRB.ZIP
  4931.                                                        .
  4932.                                                        .
  4933.                                                        .
  4934.                                                    interRRG.ZIP
  4935.         RR is the release number (at the time I wrote this, RR was 60).
  4936.  
  4937.     Ralf's Brown E-mail is: ralf@pobox.com
  4938.  
  4939.     Perhaps Ralf's Brown Interrupt List is too much detailed, so you may try
  4940.   also the Interrupt List that comes with HelpPc (see README.1ST for further
  4941.   details)
  4942.  
  4943. :··About
  4944. %   VIDEO HANDLING FUNCTIONS ver 2.0
  4945.  
  4946.  Copyright (C) 1998, 1999 by Márcio A. A. Fialho.
  4947.  Email = jlfialho@iconet.com.br or jlfialho@yahoo.com (alternate)
  4948.  http://pessoal.iconet.com.br/jlfialho
  4949.  Freeware / Public Domain.